Search code examples
androideclipsedebuggingandroid-widgetbreakpoints

Prevent "Scheduling restart of crashed service" for widget when debugger on breakpoint


I've set up Eclipse (3.7.2) with the Android Development Toolkits (16.0.1), including Dalvik Debug Monitor Service (16.0.1), as directed in different more or less official tutorials.

If I write a "standard" Android application, with a launcher Activity, then I can set breakpoints in my code, run it on a Virtual Android Device, and the break points break as expected, and I can spend my whole night debugging code if I want.

The problem comes when instead of a "standard" Android application, I start playing around with an Android home screen widget, which does not have a launcher Activity. If I want to debug my code, I still can set breakpoints easily. Let's say I put a breakpoint straight in the onUpdate of my implementation of my AppWidgetProvider, and I test it by adding an instance of my widget to the AVD. The breakpoint doesn't break. I figure, this is because in the Debug Configurations, the launch action for my widget is "do nothing", as there is no Activity I can select.

Googling around, I found that when my AVD was running, I could go to the DDMS view in Eclipse, and in its Devices tab, I could select my widget process, and click on a cute green bug "debug selected process". If after that, I create an instance of my widget in the AVD, then the execution does break on my breakpoint.

But here comes my next problem: when this happens, I have about a few seconds in the debugger, before Android decides that my widget process has hung (which is true), and should be shot (which is not true)! Therefore my question is: how to prevent the system from shooting my process stopped at a breakpoint?

Note: In the log I get that sort of notification:

06-11 17:02:19.900: W/ActivityManager(59): Scheduling restart of crashed service [...]

Solution

  • Start a service that doesn't run on the main thread (such as IntentServcie) from your widget receiver (onUpdate()). Do all your work there.