开发者

how to run Specific activity in android emulator?

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.

c开发者_如何学运维an 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.


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


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.


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

    }


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜