我有一个登录屏幕,希望应用程序看起来好像在应用程序关闭/销毁/电话呼叫等后仍然在内部屏幕上“登录”.
我有一个首选项对象来保存登录或注册后的值.我在所有关键屏幕onResume()方法中读取了首选项值.
登录后(例如):
SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("sessionId",application.currentSessionId);
editor.putString("userId",application.currentUserId);
editor.putString("userEmail",application.currentUserEmail);
editor.putString("siteUserId",application.currentSiteUserId);
editor.commit();
在活动的onResume()内:
(即在内部屏幕内)
SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(activity);
application.currentSessionId = app_preferences.getString("sessionId","");
application.currentUserId = app_preferences.getString("userId","");
application.currentUserEmail = app_preferences.getString("userEmail","");
application.currentSiteUserId = app_preferences.getString("siteUserId","");
注意.我有应用程序“全局”变量,即application.currentSessionId,你可以只替换你的变量
尝试类似的东西,也许你没有保存或正确检索值,因为SharePreferences应该工作