Search code examples
androidmultithreadingwidgetandroid-appwidgetintentservice

Android IntentService - execute other thread in it


I have an App Widget that updates itself through an IntentService (started from AppWidgetProvider)

This IntentService detects if it is time to update (weekly or by refresh button click) and asynchronously calls a network operation, else it repaints the widget. The IntentService register itself as the callback handler of the network operation, so that it can repaint after the response arrives.

The widget updates OK, however i've had some problems with the widget.

I was wondering if it is wrong to call another asynchronous thread sending the intent itself as listener; because the intenthandler thread stops after onHandleIntent finishes running.

What would be the best way to manage this?


Solution

  • Why run it async when you're already off the main thread? Can you run in synchronously and let the intentservice do what it would do in the callback when it finishes?

    You're not guaranteed that the intent service will still be around, and should not perform async actions in it that call back to the intent service.