I have a IntentService
that does a long work, it takes about 15 minutes to be done. It is a synchronization process to get new data from my server.
When this service starts, I start a activity too, to display the progess.
This activity creates a BroadcastReceiver
, that intercepts messages sent from the service about the process progress.
If I leave the app doing it job, after a while the SO switch off the screen.
When I switch on the screen again, after about 15 minutes, the service has been already done, but the progress appears to be out of date. The BroadcastReceiver
has stopped to work, and my END OF SYNCHRONIZATION
message hasn't been received by the activity.
The problem is that, at this message I start the main activity again to leave the user to use the app again.
How can I solve this?
I solved with this http://developer.android.com/intl/pt-br/guide/components/services.html#Foreground .
My service
My activity
Broadcast Receivers are not made to do long duration work.
The lifetime of a broadcast receiver lasts about 10-15 seconds.
A recommended or typical use of a broadcast receiver is to
In your case you should start a service from your broadcast Receiver and do all the work in that service.