public class

PowerManager.WakeLock

extends Object
java.lang.Object
   ↳ android.os.PowerManager.WakeLock

Class Overview

Class lets you say that you need to have the device on.

Call release when you are done and don't need the lock anymore.

Summary

Public Methods
void acquire()
Makes sure the device is on at the level you asked when you created the wake lock.
void acquire(long timeout)
Makes sure the device is on at the level you asked when you created the wake lock.
boolean isHeld()
void release()
Release your claim to the CPU or screen being on.
void setReferenceCounted(boolean value)
Sets whether this WakeLock is ref counted.
void setWorkSource(WorkSource ws)
String toString()
Returns a string containing a concise, human-readable description of this object.
Protected Methods
void finalize()
Called before the object's memory is reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void acquire ()

Since: API Level 1

Makes sure the device is on at the level you asked when you created the wake lock.

public void acquire (long timeout)

Since: API Level 1

Makes sure the device is on at the level you asked when you created the wake lock. The lock will be released after the given timeout.

Parameters
timeout Release the lock after the give timeout in milliseconds.

public boolean isHeld ()

Since: API Level 1

public void release ()

Since: API Level 1

Release your claim to the CPU or screen being on.

It may turn off shortly after you release it, or it may not if there are other wake locks held.

public void setReferenceCounted (boolean value)

Since: API Level 1

Sets whether this WakeLock is ref counted.

Wake locks are reference counted by default.

Parameters
value true for ref counted, false for not ref counted.

public void setWorkSource (WorkSource ws)

Since: API Level 9

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

Protected Methods

protected void finalize ()

Since: API Level 1

Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable