Class WakefulBroadcastReceiver
- java.lang.Object
-
- android.content.BroadcastReceiver
-
- com.batch.android.compat.WakefulBroadcastReceiver
-
- Direct Known Subclasses:
BatchPushMessageDismissReceiver,BatchPushMessageReceiver,BatchPushReceiver
public abstract class WakefulBroadcastReceiver extends android.content.BroadcastReceiverHelper for the common pattern of implementing aBroadcastReceiverthat receives a device wakeup event and then passes the work off to aService, while ensuring that the device does not go back to sleep during the transition.This class takes care of creating and managing a partial wake lock for you; you must request the
Manifest.permission.WAKE_LOCKpermission to use it.Example
A
WakefulBroadcastReceiveruses the methodstartWakefulService()to start the service that does the work. This method is comparable tostartService(), except that theWakefulBroadcastReceiveris holding a wake lock when the service starts. The intent that is passed withstartWakefulService()holds an extra identifying the wake lock.The service (in this example, an
IntentService) does some work. When it is finished, it releases the wake lock by callingcompleteWakefulIntent(intent). The intent it passes as a parameter is the same intent that theWakefulBroadcastReceiveroriginally passed in.
-
-
Constructor Summary
Constructors Constructor Description WakefulBroadcastReceiver()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancompleteWakefulIntent(android.content.Intent intent)Finish the execution from a previousstartWakefulService(android.content.Context, android.content.Intent).static android.content.ComponentNamestartWakefulService(android.content.Context context, android.content.Intent intent)Do aContext.startService, but holding a wake lock while the service starts.-
Methods inherited from class android.content.BroadcastReceiver
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, goAsync, isInitialStickyBroadcast, isOrderedBroadcast, onReceive, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
-
-
-
-
Method Detail
-
startWakefulService
public static android.content.ComponentName startWakefulService(android.content.Context context, android.content.Intent intent)Do aContext.startService, but holding a wake lock while the service starts. This will modify the Intent to hold an extra identifying the wake lock; when the service receives it inService.onStartCommand, it should pass back the Intent it receives there tocompleteWakefulIntent(android.content.Intent)in order to release the wake lock.- Parameters:
context- The Context in which it operate.intent- The Intent with which to start the service, as perContext.startService.
-
completeWakefulIntent
public static boolean completeWakefulIntent(android.content.Intent intent)
Finish the execution from a previousstartWakefulService(android.content.Context, android.content.Intent). Any wake lock that was being held will now be released.- Parameters:
intent- The Intent as originally generated bystartWakefulService(android.content.Context, android.content.Intent).- Returns:
- Returns true if the intent is associated with a wake lock that is now released; returns false if there was no wake lock specified for it.
-
-