I have found this line in an application source code but i cant figure out the meaning of the bitwise or inclusive operator "|" between the two flags.
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
I did not also understand the meaning of this operator |= in the following line:
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Someone could help me plz.
I'd started my answer while no-one else had answered, so I decided to finish it anyway...
The pipe and ampersand | and &
perform the OR
and AND
operations respectively.
You'll be used to seeing ||
and &&
, which perform the boolean logic OR
and AND
, and the use of a single | or &
is a bitwise operation.
If you look on the flag documentation, the flag for clear_top is 0x04000000, and single_top is 0x20000000.
The operation which you are performing is therefore: 0x04000000 OR 0x20000000 = 0x24000000
Which sets the required bits in the intent to use both of the desired flags.
The a |= b
operator is the overloaded equivalent of a = a | b
, similar to the usage of +=
, --
or ++
, which you should be used to seeing elsewhere
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With