首页 > getSharedPreferences无法在另外一个activity获取到值

getSharedPreferences无法在另外一个activity获取到值

SharedPreferences settings = getSharedPreferences("user",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("uid",String.valueOf(id));
editor.commit();

跳转到另外一个Activity无法获取值,只能退出app后才有值


用这种方式去创建 PreferenceManager.getDefaultSharedPreferences(this); 在程序中只有一个文件,

this.getSharedPreferences (String name, int mode) 这样的方式去创建的话 是通过activity 去创建的,以第一参数的name为文件名保存在系统中。

【热门文章】
【热门文章】