This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
Bug 863103 - Add BackgroundService runIntentInService() and WakeLock #307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@rnewman r?
After reviewing Google's Cloud Messaging (GCM) implementation, here are two BackgroundService additions that may be useful:
Add runIntentInService() utility method to ensure the original Intent's extras are copied to rebroadcast Intent:
https://code.google.com/p/gcm/source/browse/gcm-client/src/com/google/android/gcm/GCMBaseIntentService.java?r=3f8285f108caecf9ee040cdadda3a024b81f7e3e#268
Add WakeLock to ensure BackgroundService receives the Intent after the BroadcastReceiver returns.
GCM releases its WakeLock at the end of onHandleIntent():
https://code.google.com/p/gcm/source/browse/gcm-client/src/com/google/android/gcm/GCMBaseIntentService.java?r=3f8285f108caecf9ee040cdadda3a024b81f7e3e#241
Can we safely assume that Android will always call our onDestroy() method?� If not, then we risk leaking a WakeLock.
This change is tricky because it relies on every subclass calling super.onHandleIntent() and super.onDestroy() (if the subclass has overridden those methods). Also, we might be able to remove the ugly EXTRA_RELEASE_WAKE_LOCK extra if we assume BackgroundServices are always launched from runIntentForService() and thus called acquireWakeLock().