adb

Starting an app in debug mode

How to wait for debugger before starting the app?

Let’s say your launch activity is called MainActivity, in your app com.example.myapp. In the manifest:

<activity
        android:name=".MainActivity"
        >
        <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
</activity>

Now let’s say you want to launch the app, so that it waits for the debugger to connect before the app really starts.

You can use adb shell to achieve that.
In our case, simply run:

adb shell am start -D -n com.example.myapp/com.example.myapp.MainActivity

Now, all that’s left is to attach your favorite debugger. For example, if you use Intellij or Android Studio go to Run->Attach debugger to Android process-> select your app package name


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow