Is it possible to start activity through adb shell? [duplicate]

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


Launch adb shell and enter the command as follows

am start -n yourpackagename/.activityname

eg:

MyPackageName is com.example.demo

MyActivityName is com.example.test.MainActivity

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

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.