Skip to content Skip to sidebar Skip to footer

Issue With Boolean On Shared Preferences

I am currently trying to start a service based on the boolean false or true when the phone boots up. The issue is if i use getBoolean boolean isPhysicalSirenFlagged = sp.getBoolea

Solution 1:

Have it set to false instead, obviously what ever you are doing is not commiting a change to the SharedPrefereces to indicate the flag. By using false as a default, you will prevent the accidental true assignment to the flags. Truthfully, you should be using int flags (or preferred an enum) to represent this. It is a much safer way of determining the state the device is in. for example:

int NO_STATE    = 0
int IS_THEFTED  = 1
int IS_WAILING  = 2

or

enum State {
    NONE, THEFTED, WAILING;
}

Post a Comment for "Issue With Boolean On Shared Preferences"