0

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 [...]
Balint
  • 1,405
  • 1
  • 9
  • 12

1 Answers1

1

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

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • This is already what I am doing. For the test, I downloaded the "official" widget example: http://android-developers.blogspot.co.uk/2009/04/introducing-home-screen-widgets-and.html and when putting my breakpoint in `onStart` of the `Service`, I still hit my problem `Scheduling restart of crashed service com.example.android.simplewiktionary/.WordWidget$UpdateService` – Balint Jun 22 '12 at 07:54
  • Well, this example is pretty old and the Service is still running in the main thread. Implement it as an `IntentService` to have it start a worker thread automatically. – Nikolay Elenkov Jun 22 '12 at 07:57
  • Thanks very much, that did the trick! Note for anyone stumbling on this issue in the future, IntentService needs both nullary and unary constructor, as per http://stackoverflow.com/questions/2120699/newinstance-failed-no-init – Balint Jun 23 '12 at 16:57