I just want to know if the night mode in Android needs sqlite? or there's another way to save the mode in it when the user close the app and reopen it again it will save the mode pls help
If there's another way please share it with me Thanks
I just want to know if the night mode in Android needs sqlite? or there's another way to save the mode in it when the user close the app and reopen it again it will save the mode pls help
If there's another way please share it with me Thanks
No, sqlite is not needed.
Local application settings such as night mode preference are typically stored in SharedPreferences
.
You can just save a variable in the SharedPreferences of the app for the preferred user settings and set theme on launch. Go through the documentation to know more .SharedPreferences
Please, check Shared Preferences. This is key-value storage and it's exactly suited for such needs.
As general practice - create some SharedPrefManager and move all logic with shared preferences there. Like in this answer.
Write this code on the first page that runs
SharedPreferences pref = getApplicationContext().getSharedPreferences("nightMode", 0);
if(pref.getBoolean("mode",false)){
// code change ui to night
}
and Write this code on the night mode switch
SharedPreferences pref = getApplicationContext().getSharedPreferences("nightMode", 0);
pref.edit().putBoolean("mode",true).apply();
Just as easily