SharedPreferences return only default value

后端 未结 3 1379
一整个雨季
一整个雨季 2021-01-19 13:15

So instead of creating a database, I\'m storing the data using SharedPreference.

My code is below:

   SharedPreferences.Editor editor =          


        
相关标签:
3条回答
  • 2021-01-19 14:01

    Do you use shared preferences in two different activieties of one app ?

    Also try to specify preferences name, or use some Manager to handle all preferences, all this explained here

    0 讨论(0)
  • 2021-01-19 14:01
    editor.putInt("favid"+id, 1);
    

    what's about id is equals to 0? here you are reading starting from 1

     for (int i = 1; i < 19; i++) {
    
    0 讨论(0)
  • 2021-01-19 14:05

    See docs about getPrefernces method:

    Retrieve a SharedPreferences object for accessing preferences that are private to this activity.

    So, if you want to share preferences between activities you should use getSharedPreferences with specified name.

    0 讨论(0)
提交回复
热议问题