8

I inherited some code that is having an issue when importing files only when the app isn't running. I was wanting to see if there was a way to hookup/monitor an app before it runs and be able to step through code.

The problem only comes about when importing starts the app. I seen that I could use DDMS for debugging logcat and the heap but I need to be able to step through the code with the debugger... at least I think I do.

enter image description here

Bryan Williams
  • 693
  • 1
  • 10
  • 27
  • 1
    Like, stepping through the onCreate() method? – Justin Jasmann Feb 22 '13 at 20:28
  • @JustinJasmann Yes, I would like to set a breakpoint before the app runs and have that be triggered when the import starts the app. – Bryan Williams Feb 22 '13 at 20:30
  • 1
    You can definitely set a breakpoint in the onCreate() method. – Justin Jasmann Feb 22 '13 at 20:35
  • @JustinJasmann I'm not sure if I'm getting my point across very well, sorry. I know I can put a breakpoint in the onCreate() but when you start the debugger it starts the app. I need to have it wait for the import of the file to start the app. Does that make sense? – Bryan Williams Feb 22 '13 at 20:38
  • Sorry Bryan. I'm totally confused. "wait for the import of the file to start the app" - huh? – Simon Feb 22 '13 at 20:41
  • What is the import of what file? Is it running in a service? – codeMagic Feb 22 '13 at 20:42
  • 1
    Same question as these two, what exactly is waiting on files? I'm assuming it's a different background service that's actually launching your app? – Justin Jasmann Feb 22 '13 at 20:47
  • I have a zip file that the user downloads and when they click it they get an option to open it with my app. This error that I am seeing is only happening when the app gets opened via the open file in app menu. I will included a image above. – Bryan Williams Feb 22 '13 at 20:50
  • you need to start a new question. Your problem is "app crashes when started through an implicit intent". Please include the stack trace of the exception from logcat. – Simon Feb 22 '13 at 20:51
  • Sorry for the disconnect here. I have only been an Android programmer for a week. I came from programming on iOS for the past couple years. – Bryan Williams Feb 22 '13 at 20:52
  • 1
    I'm pretty sure you can start the debugger in Eclipse, then choose to unzip the file with your application (on your device or emulator), then whenever your main activity starts, it will hit the breakpoint in onCreate() or wherever you wish. – Justin Jasmann Feb 22 '13 at 21:03

4 Answers4

16

In several latest API version (at least 21+), you can find:

Settings -> Developer options -> Wait for debugger.

which helps you stop for debugger during a debug application's startup

Shubham Chaudhary
  • 47,722
  • 9
  • 78
  • 80
  • 2
    Also, before clicking `Wait for debugger` you need to click `Select debug app` (a preference above the `Wait for debugger`) to choose which app should be waiting for the debugger. – Bartek Lipinski Jul 09 '18 at 13:03
  • 2
    It works perfect! (You have to do this from the phone developer options) – Andy Oct 22 '19 at 13:16
6

Once the app is running you can go to DDMS processes and click the bug icon. If you need to do it right before early code is run, you could put a sleep in before that code to give you a chance to start debugging your process. But if this sounds like too much trouble, logging is probably a better option.

Edwin Evans
  • 2,726
  • 5
  • 34
  • 47
  • 3
    Actually, I ran across a better way of doing this. See Wait for Debugger at http://developer.android.com/tools/debugging/debugging-devtools.html – Edwin Evans Apr 13 '13 at 18:52
0

Shift+F9 should start in Debug mode, which will attach the debugger before running. Alternatively, Run -> Debug '[app name]'

Mars
  • 2,505
  • 17
  • 26
-2

for android studio you can attach debugger by clicking on this icon and chose the right process.

attach debugger to android

Omar Abdan
  • 1,901
  • 17
  • 29