You may want to observe/ debug behaviour related to your app's Activity, Broadcast Receiver or Service being launched by an Intent, without any side effects of the application already running. For example, I was testing push notifications, and wanted to debug the case where no other application components was running (Activity, Service), and only the Broadcast Receiver declared in my
AndroidManifest.xml was launched in response to the push notification message. This is only possible if the application hasn't been launched yet by Android Studio.
The trick is prevent your app from launching until the debugger is attached, and then to attach the debugger. This means you won't miss anything between the app launching and you attaching the debugger.
If you are trying to test push notifications, send a push notification to your device. For example, I have an iOS application which can send a push notification to other devices. Your app should not actually launch, but it would be waiting for the debugger:
If you are working on Flutter, you should have 2 Android Studio windows open:
project_dir/android, or for flutter package plugins,
At this point, you should press Flutter attach in your
project_dir Android Studio window first. Nothing will happen until after you attach your Android app debugger, below. You should currently only see, for example "Waiting for a connection from Flutter on SM G991B...". SM G991B is my physical device, and Samsung S21.
Click the Attach debugger to Android Process, and in the window, select your application by its application ID. Your application should launch, and your debugger breakpoints will work. If running Flutter, your Flutter debugger in Android Studio will also