0

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?

Bisho
  • 5
  • 4
  • Your splash screen is started before you check the value of the checkbox i think. – greenapps Nov 18 '14 at 15:50
  • No..i already set the checkbox to true which should start the first activity as it first start up...in the `if(Global.ENABLE_APP_LOCK==1)` – Bisho Nov 18 '14 at 16:31
  • You set the checkbox to true and then invoke a splash sceen? What kind of scenario is that? I would think: You start your app while the CheckBoxPreference is true. And then you start an activity. Better show more code so we can inspect the sequence as that is unclear now. I referred to the 'check' in `in my MainActivity i check the value of the checkbox as follows`. – greenapps Nov 18 '14 at 16:43
  • Dude...it is a checkbox preference, if it is checked that means it will change the value of the global var to 1 which will start the first activity next time the app is launched .. – Bisho Nov 18 '14 at 16:57
  • So about the sequence: the global will be set to 1. Then you close your app. Then you restart and the global is .. 0. Strange? No. Ofcourse it is 0 then. – greenapps Nov 18 '14 at 17:14

0 Answers0