1

Android: how to debug app's start-up process

 1 year ago
source link: https://stackoverflow.com/questions/16929391/android-how-to-debug-apps-start-up-process
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I am investigating some issues which happen during my app's startup process, but DDMS won't start the debug mode until the process has started, is there a way I can capture the events earlier?

asked Jun 4, 2013 at 23:59

4 Answers

I know that this is a couple of years late, but for any future searches:

Putting WaitForDebugger into your code is one way.

Unlocking developer options (by tapping on the build number in system information on the android device) in Settings allows us to select an application for debugging and then opt to wait for a debugger whenever the program is launched. This allows us do the equivalent of adding and removing WaitForDebugger without modifying and reinstalling the code each time.

answered May 29, 2015 at 15:09

For Android Studio, here is what worked for me:

android.os.Debug.waitForDebugger();

Where you want to start debugging.

  1. Then add a breakpoint just after it in your code
  2. Compile your app and pass it to your device
  3. Restart your device
  4. Once it's up, attach the debugger:

  5. Start debugging

answered Dec 19, 2017 at 20:20

Android can wait for the debugger to attach to your application before the app gets launched. This is a developer option called Wait for debugger.

Steps

  • Enable developer options (tap build version 7 times)

  • Enable USB debugging

  • Install your application onto your device using debug mode

  • In developer options: Press Select debug app and select the app

  • Enable Wait for debugger, as shown in screenshot:

    enter image description here
  • Launch your app:

    • e.g. If testing app launch from terminated state from a push notification, send that push notification to the device.
    • e.g. If testing app launch from Google Assistant, use the Google Assistant to trigger this.
  • The app would not launch yet, instead a dialog would show up:

    enter image description here
  • Attach the debugger, by pressing the Attach Debugger to Android Process button enter image description here

My situation

For anyone interested/ for my future reference: I wanted to debug my Android application receiving a push notification message when the app was in the terminated state. It was actually a Flutter app running on Android, so this is relevant for both Android and Flutter.

enter image description here

I have revoked the API key revealed in this GIF.

If Wait for debugger is enabled, sometimes you need to detach or close Android Studio's debugger and re-attach it if you want to handle a subsequent application launch successfully. Otherwise, the app would never launch.

Notice, I send a push notification from a device (left device, iOS), and the push notification causes the app to launch on the (right device, Android). Then I attach the debugger, and the program pauses at the breakpoint I set inside FirebaseMessagingReceiver.

I wrote another version of these steps here.

answered Sep 12, 2021 at 12:05

You should implement your own Application class which extends Application and override the methods onCreate and so.. . This class will be your starting point of your app.

also set it as your application in the manifest.

answered Jun 5, 2013 at 0:30

Your Answer

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Email and Password

Post as a guest

Name
Email

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK