eclipse 如何在android模拟器中运行特定活动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2176037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:22:07  来源:igfitidea点击:

how to run Specific activity in android emulator?

androideclipseandroid-activity

提问by UMAR

i have created 4 activities in eclipse now i want to run activity 1, 2,3 ,4 repectively one by one in emulator for testing.

我已经在 Eclipse 中创建了 4 个活动,现在我想在模拟器中分别运行活动 1、2、3、4 进行测试。

can any one guide me how can i run those all???

任何人都可以指导我如何运行所有这些???

when i press run button it only runs first activity.

当我按下运行按钮时,它只运行第一个活动。

any help would be appriciated.

任何帮助都会受到帮助。

采纳答案by fupsduck

public void onClick(View v) {

    Intent i;

    i = new Intent(this, YourActivity1.class);
    startActivity(i);

    i = new Intent(this, YourActivity2.class);
    startActivity(i);

    i = new Intent(this, YourActivity3.class);
    startActivity(i);

    i = new Intent(this, YourActivity4.class);
    startActivity(i);
}

回答by ddcruver

You could try startActivityForResult but you may need to possibly modify your program your applications to handle this. I would suggest using one of the android sdk tools called am (activity manager). In the adb shell:

您可以尝试 startActivityForResult 但您可能需要修改您的应用程序来处理此问题。我建议使用一种名为 am(活动管理器)的 android sdk 工具。在 adb 外壳中:

# am start -n package-name/activity-1-name
# am start -n package-name/activity-2-name
# am start -n package-name/activity-3-name
# am start -n package-name/activity-4-name

回答by Thomas v d O

Go to the AndroidManifest.xml and cut

转到 AndroidManifest.xml 并剪切

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

from the Main Activity. Then paste it into the Activity that you want to start.

从主要活动。然后将其粘贴到您要启动的 Activity 中。

回答by RAJESH KUMAR ARUMUGAM

To Run A specific Activity First Change the Activity Name In the setContentView within the Main Activity.java

要运行特定的活动,首先在 Main Activity.java 的 setContentView 中更改活动名称

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.Your_Activity_Name);

    }

回答by ddcruver

Android SDK includes the JUnit framework for writing unit tests. You can use the package android.test packages to run activities under JUnit. It may be overkill for what you want but eventually you may need this functionality.

Android SDK 包含用于编写单元测试的 JUnit 框架。您可以使用包 android.test 包在 JUnit 下运行活动。对于您想要的东西来说可能有点矫枉过正,但最终您可能需要此功能。

References:

参考:

http://junit.sourceforge.net/

http://junit.sourceforge.net/

http://mylifewithandroid.blogspot.com/2008/11/junit-in-android.htmlhttp://mylifewithandroid.blogspot.com/2008/11/junit-in-android.html

回答by sweluhu

Go to the Android Manifest file under your workspace root and double click on it to open. Go to the AndroidManifest.xml tab and change the name of the first activity to whatever activity you want to launch at run. Also make sure you rename that first activity to the other activity so ADT doesn't throw errors. Basicall, switch their names in the xml file. I had to do it because I wanted to test each activity individually before linking them. Let me know if you have any other question.

转到工作区根目录下的 Android Manifest 文件,然后双击它打开。转到 AndroidManifest.xml 选项卡并将第一个活动的名称更改为您要在运行时启动的任何活动。还要确保将第一个活动重命名为另一个活动,以便 ADT 不会引发错误。基本上,在xml文件中切换他们的名字。我必须这样做,因为我想在链接它们之前单独测试每个活动。如果您有任何其他问题,请告诉我。