|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectandroid.content.BroadcastReceiver
android.support.v4.content.WakefulBroadcastReceiver
public abstract class WakefulBroadcastReceiver
Helper for the common pattern of implementing a BroadcastReceiver
that receives a device wakeup event and then passes the work off
to a Service, 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_LOCK
permission to use it.
A WakefulBroadcastReceiver uses the method
startWakefulService()
to start the service that does the work. This method is comparable to
startService(), except that
the WakefulBroadcastReceiver is holding a wake lock when the service
starts. The intent that is passed with
startWakefulService()
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 calling
completeWakefulIntent(intent). The intent it passes as a parameter
is the same intent that the WakefulBroadcastReceiver originally
passed in.
| Constructor Summary | |
|---|---|
WakefulBroadcastReceiver()
|
|
| Method Summary | |
|---|---|
static boolean |
completeWakefulIntent(android.content.Intent intent)
Finish the execution from a previous startWakefulService(android.content.Context, android.content.Intent). |
static android.content.ComponentName |
startWakefulService(android.content.Context context,
android.content.Intent intent)
Do a Context.startService, but holding a wake lock while the service starts. |
| Methods inherited from class android.content.BroadcastReceiver |
|---|
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, onReceive, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WakefulBroadcastReceiver()
| Method Detail |
|---|
public static android.content.ComponentName startWakefulService(android.content.Context context,
android.content.Intent intent)
Context.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 in Service.onStartCommand, it should pass back the Intent it receives there to
completeWakefulIntent(android.content.Intent) in order to release
the wake lock.
context - The Context in which it operate.intent - The Intent with which to start the service, as per
Context.startService.public static boolean completeWakefulIntent(android.content.Intent intent)
startWakefulService(android.content.Context, android.content.Intent). Any wake lock
that was being held will now be released.
intent - The Intent as originally generated by startWakefulService(android.content.Context, android.content.Intent).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||