这在这里的android通知中使用:
http://www.vogella.com/articles/AndroidNotifications/article.html#notificationmanager_configure
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
Run Code Online (Sandbox Code Playgroud)
按位或与赋值.
int a = 6, b = 5;
a = a | b;
// is equivalent to
a |= b;
Run Code Online (Sandbox Code Playgroud)
在像Android这样的系统中,将许多不同的布尔属性压缩为单个整数值通常是有意义的.值可以与之结合|并进行测试&.
// invented constants for example
public static final int HAS_BORDER = 1; // in binary: 0b00000001
public static final int HAS_FRAME = 2; // 0b00000010
public static final int HAS_TITLE = 4; // 0b00000100
public void exampleMethod() {
int flags = 0; // flags = 0b00000000
flags |= HAS_BORDER; // 0b00000001
flags |= HAS_TITLE; // 0b00000101
if ((flags & HAS_BORDER) != 0) {
// do x
}
if ((flags & HAS_TITLE) != 0) {
// do y
}
}
Run Code Online (Sandbox Code Playgroud)