我的安卓应用程序正在被安卓操作系统杀死,当它在后台为sometime.So启动时,它是一个空屏幕,因为当操作系统杀死process.Unfortunately时,所有的数据都已经被擦除了,我没有在SQLite或共享首选项中存储任何数据。最好的方式是显示UI组件的数据,即使在应用程序被终止之后?(不幸的是,由于敏感数据/根据要求,无法实现SQLite )。
1,我观察到,每当在基本活动oncreate方法中发生这种情况时,我都会在oncreate方法中接收到savedInstanceState。因此,我只是从那里调用启动器方法,应用程序就像预期的那样工作。但这是完美的实现方式吗?
发布于 2018-12-21 12:33:58
如果我理解正确的话,关于保存简单状态和从简单状态恢复,您使用savedInstanceState应该是非常正确的。
static final String STATE_SCORE = "playerScore";
static final String STATE_LEVEL = "playerLevel";
// ...
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}然后,当应用被终止并重新启动时:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // Always call the superclass first
// Check whether we're recreating a previously destroyed instance
if (savedInstanceState != null) {
// Restore value of members from saved state
mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
} else {
// Probably initialize members with default values for a new instance
}
// ...
}请参考here了解更多详细信息。
发布于 2018-12-21 11:59:41
最有可能的是,服务器端会话在此期间已经过期。
onPause()上的用户,然后再次登录onResume().service使服务器端会话保持活动状态。https://stackoverflow.com/questions/53878928
复制相似问题