Start an Activity with ADB

Sushant Kumar
1 min readJul 8, 2020

--

While working on an application, sometime happens like you have to work on some screens using Activity components but that screen has no entry point during your feature development. How do you open that screen during testing and debugging?

The first thing comes to mind to make that component MAIN and Default to open that screen on the starting of the application, but it has a headache of removing it. Another way you try to add a fake entry point to open that screen but it also caused problems if you forgot to remove that or if the code is too complex.

With ADB (Android Debug Bridge) you can perform several tasks on a connected device (or emulator). And you can start an activity from the command line to test that particular component.

You can use the start command from Activity Manager (am) a.k.a the ADB shell am start -n command (via ADB) specifying the app package name and the component name as defined in the manifest.

adb shell am start -n com.example.demo/.FeatureActivity

If the screen within a module, you can specify the app package name and the full component name as defined in the module manifest itself to open.

adb shell am start -n com.example.demo/com.example.featuremodule.FeatureActivity

You can add other parameters like ACTION (-a android.intent.action.MAIN) and CATEGORY (-c android.intent.category.LAUNCHER).

You can also send data to that intent , see documentation here.

--

--

Sushant Kumar

Software Engineer from IIIT ALLAHABAD. Currently working as Android developer at Grab. Passionately curious about developing apps and learn new things.