Downloading Data Using Intentservice - Lifecycle Changes
Tl;dr How to know when an IntentService has finished downloading upon returning to the Activity which listens to its result using a BroadcastReceiver? I'm moving to implementing d
Solution 1:
use sendStickyBroadcast to send a sticky broadcast. This broadcast is held by the system.
Solution 2:
I wasn't really convinced by using SharedPreferences, static variables and other 'hacky' solutions.
I did find however that you can supply a ResultReceiver
- which is parcelable - which you can use to notify your task is finished. It receives a Handler
to specify the thread the result is handled on.
The advantage of this, is that you can save the ResultReceiver
during onSaveInstanceState
. Using some clever tricks you can certainly make this work. I have created an experimental library which facilitates this tactic: https://github.com/nhaarman/Ergo
Post a Comment for "Downloading Data Using Intentservice - Lifecycle Changes"