Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach Eclipse debugger to restarted application

I am testing the onsave/onrestore mthods of my android application.

To do this I phone my device and see that it kills the process and then I hang up. :) I see that it restarts the application.

Question is: how do I cause it to restart in debug mode so I can step through the restore process? Is there a way to tell it to automatically attach to the debugger when starting up?

like image 548
theblitz Avatar asked Oct 24 '12 15:10

theblitz


2 Answers

Use android.os.Debug.waitForDebugger();

Basically, start via debugging. Exit out of your app. Set some break points. Enter back into your app (make sure that this line is hit, so put it in your onCreate or somewhere else) and it will re-attach to the running debugger.

like image 126
Randy Avatar answered Sep 20 '22 05:09

Randy


I don't think there is a way to ensure the app restarts in debug mode. But if you are debugging your own app and don't mind adding debug code for testing you might want to add a Thread.sleep(5000) or something like this at an appropriate place in your startup methods. This should give you enough time to reconnect the debugger via the DDMS. Remove when you are done, of course ;)

like image 40
ct_rob Avatar answered Sep 21 '22 05:09

ct_rob