android sharedpreferences set value

前端 未结 1 539
别跟我提以往
别跟我提以往 2021-01-31 03:19

I have preferences page. It has field \'Show info screen\' (as checkbox).

I have also info page which also should have checkbox \'Show me again\'.

As I\'ve unde

相关标签:
1条回答
  • 2021-01-31 03:55

    It depends on whether you are after one set of preferences for your application, or one set per activity.

    I've used code like this:

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    Editor editor = prefs.edit();
    editor.putBoolean(PREF_NAME, false);
    editor.commit();
    

    and

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    if (prefs.getBoolean(PREF_NAME, true)) {
        // etc
    }
    
    0 讨论(0)
提交回复
热议问题