Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 840
androidkc Avatar asked Jun 04 '13 23:06

androidkc


People also ask

What starts the app with the debugger attached to the app process?

You usually start a debugging session using the Debug button or menu option. However, if you started an app by running it, you can attach a debugger to the running app without needing to restart it. To do this, click Attach Debugger to Android Process.


2 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.

like image 183
Michael Hays Avatar answered Oct 29 '22 20:10

Michael Hays


For Android Studio, here is what worked for me:

  1. Add

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:enter image description here

  5. Start debugging

like image 29
hiddeneyes02 Avatar answered Oct 29 '22 20:10

hiddeneyes02