3

Helo !

I am working right now with an application that uses BOOT_COMPLETED receiver.

So if I want to debug this application with some breakpoints in its class, I have to reboot my phone and connect to it in the proper time, but I am always too late.

Have you got any better solutions how to debug my application exact when it starts its lifetime with device reboot case ?

Thanks !

hsz
  • 148,279
  • 62
  • 259
  • 315

4 Answers4

7

You can wait for a debugger - Debug.waitForDebugger()

FunkTheMonk
  • 10,908
  • 1
  • 31
  • 37
  • How to use it ? can you please explain little more detail? – Karthikeyan Ve Jul 16 '20 at 07:55
  • 1
    You can place Debug.waitForDebugger() anywhere in your code, and a breakpoint on the next line -> the waitForDebugger line will block the thread until a debugger is connected (via Android studio, or however you normally do it). Once connected the thread will carry on and hit the breakpoint – FunkTheMonk Aug 11 '20 at 15:22
0

Close your emulator and Run the application directly in Debug and select the option to launch the emulator that you want to run it on.

Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84
  • Oh boy.. I am doing it all the time ;-) However problem appears when I reboot my phone. Debug is disconnected and I am too slow to reconnect it manually before first breakpoint appears. – hsz Oct 13 '11 at 10:01
0

It's an strange thing, but, what if you put a 20 sec pause or loop before your first break point?

Deitools
  • 421
  • 6
  • 16
  • This is an interesting workaround, however I am not looking for this kind of solution. – hsz Oct 13 '11 at 15:04
0

In this case logging is better solution than debuggung. I was able to see logs arising from BOOT_COMPLETE processing even in IDEA logcat window. (I also do not value step by step debugging very much, and prefer TDD approach anyway)

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
  • Sure thing, logging is way that I have to go right now, but debugging will be much better - we can do more with it. – hsz Oct 13 '11 at 15:03
  • not always. you can sort out problems with receiving on boot complete broadcast with logging, and other problems later (I personally prefer mocking, which can be seen as scripted debugging session - I also write tests before actual code) – Konstantin Pribluda Oct 13 '11 at 17:08