For example:
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK|
PowerManager.ACQUIRE_CAUSES_WAKEUP|PowerManager.ON_AFTER_RELEASE, "Alarm");
What does the ‘ | ‘ character mean?
More details about the problem:
I’m asking this because when I instantiate the wakelock with only PowerManager.AQUIRE_CAUSES_WAKEUP the program stops working, where as when I use the way above, it works fine.
I’m wondering if the cause of this is because the program ignore the ACQUIRE_CAUSES_WAKEUP tag and it ends up not being used.
In general, that symbol (
|) is a bitwise OR. It’s used in a lot of different languages and environments outside of Android.It’s usage is:
“X|Y : if X or Y is 1, then the result is 1”
In your specific case it’s being used to create a bit field. Besure to review the Android power manager code base here.
Possible flags for this API are:
These are mutually exclusive (you can only pick one), but you can “OR in” some other flags:
So once your code runs it ORs these flags together resulting in:
That’s because you have to pick one of the levels of wake lock (
PARTIAL,SCREEN_DIM,SCREEN_BRIGHT, orFULL), you’re trying to run with just one of the optional wake lock flags…