我正在尝试使用androids共享首选项,我已经记录了所有内容,下面的代码确实提交了字符串集。问题是,当我强制关闭应用程序并重新启动时,settings.getStringSet返回一个空集。任何地方都没有错误消息。
我试过PreferenceManager.getDefaultSharedPreferences,但它对我也不起作用。
感谢您的宝贵时间。
public static final String PREFS_NAME = "MyPrefsFile";
private static final String FOLLOWED_ROUTES = "followedRoutes";
稍后,当调用saved时:
public void onFollowClicked(View view){
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
Set<String> follows = settings.getStringSet(FOLLOWED_ROUTES, new HashSet<String>());
follows.add(routeId);
editor.putStringSet(FOLLOWED_ROUTES, follows);
editor.commit();
}
https://stackoverflow.com/questions/17469583
复制相似问题