2017-08-11 6 views
-2

Ich verstehe nicht, warum:Wie werden Android Service Flags verwendet?

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

weil:

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

dass flags = XY annehmen:

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

Antwort

-1

Es ist Binärflags und Sie Binäroperators benötigen (|) zu concat it, nicht logische Operatoren.

-1

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

0x01 | 0x02 ==> 0x03 ==> Binär 00000011 ===> & flag

Verwandte Themen