I want to start activity through adb shell. So that I can launch a specific activity that is needed
Asked
Active
Viewed 2.2e+01k times
152
-
http://charlesliublog.wordpress.com/2011/03/28/how-to-start-an-activity-by-adb-shell-command/ – Vajk Hermecz Nov 14 '12 at 14:24
6 Answers
279
Launch adb shell and enter the command as follows
am start -n yourpackagename/.activityname

Robin Chander
- 7,225
- 3
- 28
- 42
-
28You 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 -
15You 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
-
26Also don't forget add `android:exported="true"` line for an activity in AndroidManifest.xml file. – mbelsky Dec 01 '15 at 06:56
-
1
-
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
-
1What 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
-
11^^^ This is correct explanation rather than " am start -n yourpackagename/.activityname " youre launch activity may be in different package, than in app pakagename – UdayaLakmal Nov 21 '16 at 08:51
-
It works for me only if I add quotes: adb shell am start -n "com.example.demo/com.example.test.MainActivity" – Oleg Sokolov Nov 19 '21 at 11:52
-
Permission Denial: starting Intent ... not exported from uid xxxx – Mattwmaster58 Mar 20 '22 at 13:00
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
-
thanks a lot too, I had different build types, and strangely within the activity name, the suffix for the package isn't used :/ did learn something! – cV2 Jun 01 '17 at 12:40
-
Wow, really surprised. I can see every activity name of every app and every game even they have obfuscation! – Jemshit Oct 24 '19 at 11:20
-
2The command doesn't seem to work anymore, at least on my emulator (grep returns nothing) :( – Rick77 Mar 11 '21 at 21:59
-
2
-
Maybe true before 2020, but now on june 2022 this does not show me anything on my Android TV – 1111161171159459134 Jun 11 '22 at 20:17
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