2017-08-11 29 views
-2

我不明白爲什麼:如何使用Android服務標誌?

if((flags & (Service.START_FLAG_REDELIVERY |Service.START_FLAG_RETRY) != 0) 
    // 2 flags are present. 

因爲:

if((flags & (Service.START_FLAG_REDELIVERY |Service.START_FLAG_RETRY) != 0) 
    //it means that at least one of the 2 is present. 

假設標誌= XY:

if((flags & (Service.START_FLAG_REDELIVERY |Service.START_FLAG_RETRY) != 0) 
    //means that X!=0 or Y!=0 not X!=0 and Y!=0. 

回答

-1

它的二進制標誌,你需要二進制運算符(|)到連接它,而不是邏輯運算符。

-1

public static final int START_FLAG_REDELIVERY = 1; public static final int START_FLAG_RETRY = 2;

0x01 | 0x02 ==> 0x03 ==>二進制00000011 ===> &標記