Android CheckBoxPreference and global variables

89 views Asked by At

I am developing an android browser and i have a CheckBoxPreference that i want it to set a global int variable to 1 if checked and to 0 if unchecked here's my code: xml/prefs

 <CheckBoxPreference
                    android:key="enable_lock"
                    android:summary="Check to lock bSurfer with a password"
                    android:title="Enable app lock" android:defaultValue="true"/>

i have a Global class that has the following setter and getter:

public static int ENABLE_APP_LOCK;
public static int getENABLE_APP_LOCK() {
    return ENABLE_APP_LOCK;
}

public static void setENABLE_APP_LOCK(int eNABLE_APP_LOCK) {
    ENABLE_APP_LOCK = eNABLE_APP_LOCK;
}

in my MainActivity i check the value of the checkbox as follows

boolean appLock = getPrefs.getBoolean("enable_lock", false);
if (appLock == true) {
            Global.setENABLE_APP_LOCK(1);
        } else if(appLock==false) {
            Global.setENABLE_APP_LOCK(0);
        }

i also have a splash screen that waits for 3 seconds and checks the Global var int ENABLE_APP_LOCK if 1 start an activity if 0 start another activity

if(Global.ENABLE_APP_LOCK==1){
                Intent openAC = new Intent("com.bisho.bsurfer.PASSCHECK");
                startActivity(openAC);
                }else if(Global.ENABLE_APP_LOCK==0){
                    Intent in2 = new Intent("com.bisho.bsurfer.MAINACTIVITY");
                    startActivity(in2);
                }

The problem iam having is whether i check the CheckBox or not , it always start the second activity, can anyone please tell me what am i doing wrong?

0

There are 0 answers