I am having problems with the code below when setting a checkbox, which is checked by default. My first action is a simple splash screen, and just before showing the flow of my image, I want to check if this checkbox was disabled, if so, then I want it to be aimed directly at the main action, and by default I showing my image stream or in reverse order of that.
Currently, my popup screen is starting up regardless of whether it is checked or now. Any help would be greatly appreciated.
XML
<CheckBoxPreference android:title="@string/category_tools_startupscreen" android:summary="@string/category_tools_startupscreen_summary" android:key="boot_animation" android:order="5" android:enabled="true"/>
Splashscreen
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); if (settings.getBoolean("boot_animation", true)) { setContentView(R.layout.splash_screen); Thread splashThread = new Thread() { @Override public void run() { try { int waited = 0; // changed from 5000 to 4000 11.29 while (waited < 3000) { sleep(100); waited += 100; } } catch (InterruptedException e) { // do nothing } finally { Intent i = new Intent(); i.setClassName("com.example.app", "com.example.app.MainActivity"); startActivity(i); finish(); } } }; splashThread.start(); } else { Intent i = new Intent(); i.setClassName("com.example.app", "com.example.app.MainActivity"); startActivity(i); finish(); } }
Settings
final CheckBoxPreference checkboxPref2 = (CheckBoxPreference) getPreferenceManager().findPreference("boot_animation"); checkboxPref2.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if(newValue instanceof Boolean){ Boolean boolVal = (Boolean)newValue; SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("checked", boolVal); editor.commit(); } return true; } });
source share