1

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.

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.

6 Answers 6

3

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:

# 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
2
  • remember that activity-1-name needs to be fully qualified. eg package.name/package.name.Activity Jun 13, 2012 at 19:38
  • 1
    what you can do instead is package.name/.Activity Feb 1, 2013 at 3:53
2

Go to the AndroidManifest.xml and cut

        <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.

1

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

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

    }
0
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);
}
0

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.

References:

http://junit.sourceforge.net/

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.