admin管理员组文章数量:1123509
I am familiar with onSaveInstanceState/onRestoreInstanceState in fragments and it works perfectly for saving data when activity has been destroyed.
I have UI process, where user should pick up the phone and he would hear security code, which should enter in android application.
But, on some devices (very rarely) my app is destroyed during a telephone conversation. After restore, of course, fragment has been restored, but my okhttp session has been cleared (mainly my backend session id). So after restore I can't finish my confirmation process. Can I save this data in bundle saved in onSaveInstanceState? Or is it any better idea for deal with this issue?
I am familiar with onSaveInstanceState/onRestoreInstanceState in fragments and it works perfectly for saving data when activity has been destroyed.
I have UI process, where user should pick up the phone and he would hear security code, which should enter in android application.
But, on some devices (very rarely) my app is destroyed during a telephone conversation. After restore, of course, fragment has been restored, but my okhttp session has been cleared (mainly my backend session id). So after restore I can't finish my confirmation process. Can I save this data in bundle saved in onSaveInstanceState? Or is it any better idea for deal with this issue?
Share Improve this question asked 19 hours ago AdamNAdamN 5861 gold badge5 silver badges13 bronze badges1 Answer
Reset to default 0Yes, you can save your session data in the Bundle passed to onSaveInstanceState. However, it's not an ideal solution for data like backend session IDs, which may be more sensitive or have specific lifetimes independent of the Android app's lifecycle. Here's a detailed breakdown of potential solutions:
Using onSaveInstanceState
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("SESSION_ID", sessionId);
}
@Override
public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
if (savedInstanceState != null) {
sessionId = savedInstanceState.getString("SESSION_ID");
}
}
本文标签: android okHttponRestoreInstanceStateStack Overflow
版权声明:本文标题:android okHttp - onRestoreInstanceState - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736575485a1944846.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论