Is it possible to start activity through adb shell?

Android

Android Problem Overview


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

Android Solutions


Solution 1 - Android

Launch adb shell and enter the command as follows

am start -n yourpackagename/.activityname

Solution 2 - Android

eg:

MyPackageName is com.example.demo

MyActivityName is com.example.test.MainActivity

adb shell am start -n com.example.demo/com.example.test.MainActivity

Solution 3 - Android

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

adb shell dumpsys window windows | grep 'mCurrentFocus'

Solution 4 - Android

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.

Solution 5 - Android

adb shell am broadcast -a android.intent.action.xxx

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

Solution 6 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRajeshVijayakumarView Question on Stackoverflow
Solution 1 - AndroidRobin ChanderView Answer on Stackoverflow
Solution 2 - AndroidWooiView Answer on Stackoverflow
Solution 3 - AndroidrbennellView Answer on Stackoverflow
Solution 4 - AndroidklimatView Answer on Stackoverflow
Solution 5 - AndroidHanifView Answer on Stackoverflow
Solution 6 - AndroidJosef KufnerView Answer on Stackoverflow