How to save app settings?

前端 未结 6 1763
暖寄归人
暖寄归人 2020-12-07 03:01

How can I save the the settings of my app? Right now, for example, I have a togglebutton to turn on/off. But if I restart my phone, the toggle button is turned back on. Its

6条回答
  •  借酒劲吻你
    2020-12-07 03:12

    Use SharedPreferences as,

    To Save:

     SharedPreferences settings;
     SharedPreferences.Editor editor;
     public static final String PREFS_NAME = "app_pref";
     public static final String KEY_p_id = "KEY_test";
    
        settings = getSharedPreferences(PREFS_NAME, 0);
        editor = settings.edit();
        editor.putString(Login_screen.KEY_test, values.get(0));
        editor.commit();
    

    To Remove:

        editor.remove("KEY_test").commit();
    

提交回复
热议问题