12 September, 2010

Journey of Android Development -- Running Apps vi Adb Command Line

Ok, so you're developing the next killer app for Android. If you're anything like me, and pray you aren't, you may find you want to start your app from your development machine via the emulator.

I posted how you can install, reinstall, and uninstall your app in previous posts. This post builds on that.

Issuing an 'adb shell' command essentially executes a shell command on the emulator. If you issue a command you'll execute the command rather than enter an interactive shell.

The Activity/Intent Manager/Messenger tool allows you to start your activity through the adb command line.

The trick is to define the command arguments properly, which is done by pulling relevant information from your AndroidManifest.xml file. You need to specify the proper action and component in your command line, extracted from your Android Manifest.

Given the following AndroidManifest.xml file:

user@debian:~/Buttons$ cat -n AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.example.buttons"
4 android:versionCode="1"
5 android:versionName="1.0">
6 <application android:label="@string/app_name">
7 <activity android:name=".Buttons"
8 android:label="@string/app_name">
9 <intent-filter>
10 <action android:name="android.intent.action.MAIN" />
11 <category android:name="android.intent.category.LAUNCHER" />
12 </intent-filter>
13 </activity>
14 </application>
15 </manifest>


The action is defined in line 10, the component defined as lines 3+7 respectively.

You can start the 'Buttons' activity by specifying the following command:

adb shell am start -a android.intent.action.MAIN -n com.example.buttons/com.example.buttons.Buttons

No comments: