152

I want to start activity through adb shell. So that I can launch a specific activity that is needed

RajeshVijayakumar
  • 10,281
  • 11
  • 57
  • 84

6 Answers6

279

Launch adb shell and enter the command as follows

am start -n yourpackagename/.activityname
Robin Chander
  • 7,225
  • 3
  • 28
  • 42
  • 28
    You can find out the activity names by running `aapt dump xmltree AndroidManifest.xml` and looking through the output. – chrisvarnz Jan 14 '14 at 17:45
  • 15
    You can find the apk on the phone with `adb shell pm list packages -f` and retrieve it with `adb pull /path/to/file.apk C:\some\folder` to use with the `aapt` command Chris commented. (aapt is in build-tools) – Christopher Galpin May 29 '14 at 23:12
  • 26
    Also don't forget add `android:exported="true"` line for an activity in AndroidManifest.xml file. – mbelsky Dec 01 '15 at 06:56
  • 1
    A simpler way to find the apk on the phone would be `adb shell pm path ` – Doge Sep 28 '16 at 20:51
  • 4
    @ChristopherGalpin No need to pull the APKs, `adb shell dumpsys package` does the job. – m0skit0 Jan 30 '18 at 18:14
  • **aapt** doesn't exist on my samsung tablet... also, there may be an md5 hash prepended to the activity name. – samus Feb 02 '18 at 16:55
  • 1
    What does '-n' stands for here? I do not see any documentation on page: https://developer.android.com/studio/command-line/adb under 'Call activity manager (am)' section. – Neetesh Kumar Gupta Jul 26 '18 at 22:25
  • Neetesh - it's here https://developer.android.com/studio/command-line/adb#IntentSpec (click show all) – rbennell Dec 13 '18 at 11:50
  • @RobinChander Your command only worked as follows `am start -n yourpackagename/activityname`, i.e. the omission of `.` – Shuzheng Sep 09 '21 at 14:09
67

eg:

MyPackageName is com.example.demo

MyActivityName is com.example.test.MainActivity

adb shell am start -n com.example.demo/com.example.test.MainActivity
Wooi
  • 820
  • 6
  • 8
27

You can also find the name of the current on screen activity using

adb shell dumpsys window windows | grep 'mCurrentFocus'
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
rbennell
  • 1,134
  • 11
  • 14
26

I run it like AndroidStudio does:

am start -n "com.example.app.dev/com.example.app.phonebook.PhoneBookActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

If you have product flavour like dev, it should occur only in application package name but shouldn't occur in activity package name.

For emulator, it works without android:exported="true" flag on activity in AndroidManifest.xml but I found it useful to add it for unrooted physical device to make it work.

klimat
  • 24,711
  • 7
  • 63
  • 70
13
adb shell am broadcast -a android.intent.action.xxx

Mention xxx as the action that you mentioned in the manifest file.

spaaarky21
  • 6,524
  • 7
  • 52
  • 65
Hanif
  • 306
  • 2
  • 6
11

For example this will start XBMC:

adb shell am start -a android.intent.action.MAIN -n org.xbmc.xbmc/android.app.NativeActivity

(More general answers are already posted, but I missed a nice example here.)

Josef Kufner
  • 2,851
  • 22
  • 28