tags:

views:

468

answers:

1

During android app development, I do the following very often:

  1. Run "ant reinstall" to compile and upload an app to the emulator.
  2. Switch to the emulator window.
  3. Click on the package I just uploaded to run and test it.

Is there any way I can tell the emulator phone to run the package I just uploaded? Perhaps an "adb" command I can send to it after I've run my compile script? As a last resort, I guess I could run something that simulates the mouse click for me.

+2  A: 

You want to use the am command. Say you have a Manifest that looks kinda like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.MyApp">
    <application android:icon="@drawable/icon">
        <activity class=".MyMainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:value="android.intent.action.MAIN" />
                <category android:value="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    ...
</manifest>

you would start that with:

adb shell am start -a android.intent.action.MAIN -n com.example.MyApp/.MyMainActivity

though you may want to tell it to wait till it's ready:

adb wait-for-device shell am start -a android.intent.action.MAIN -n com.example.MyApp/.MyMainActivity

Basically you're just firing off an Intent that calls your package's main Activity.

The full documentation (from running am --help) is:

usage: am [start|broadcast|instrument|profile]
       am start [-D] INTENT
       am broadcast INTENT
       am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]
                [-w] <COMPONENT> 
       am profile <PROCESS> [start <PROF_FILE>|stop]

       INTENT is described with:
                [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
                [-c <CATEGORY> [-c <CATEGORY>] ...]
                [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
                [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
                [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
                [-n <COMPONENT>] [-f <FLAGS>] [<URI>]
fiXedd
BobbyJim
No problem. It took a little digging to figure it out, but I knew it was possible since Eclipse does it.
fiXedd