final class WakeLockUtil extends Object
Modifier and Type | Method and Description |
---|---|
(package private) static boolean |
acquireWakeLock(Context context,
PowerManager.WakeLock wakeLock,
long timeoutMillis) |
(package private) static PowerManager.WakeLock |
acquireWakeLock(Context context,
String tag,
long timeoutMillis) |
static boolean |
completeWakefulIntent(Intent intent)
Finish the execution from a previous
startWakefulService(android.content.Context, android.content.Intent) . |
(package private) static void |
releaseWakeLock(PowerManager.WakeLock wakeLock) |
static ComponentName |
startWakefulService(Context context,
Intent intent)
Do a
Context.startService , but holding a wake lock while the service starts. |
@Nullable static PowerManager.WakeLock acquireWakeLock(@NonNull Context context, @NonNull String tag, long timeoutMillis)
static boolean acquireWakeLock(@NonNull Context context, @Nullable PowerManager.WakeLock wakeLock, long timeoutMillis)
static void releaseWakeLock(@Nullable PowerManager.WakeLock wakeLock)
public static ComponentName startWakefulService(Context context, 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(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)
.