Android 中点击后退按钮时的 onSaveInstanceState
我有一个在 Android 应用程序运行时调用的活动。当用户单击后退按钮时,Activity 被销毁,我重写了 onSaveInstanceState
方法来保存 outState
以供第二次检索,但 onSaveInstanceState
当用户单击后退按钮时永远不会调用。
你知道为什么会发生这种情况吗?
I have an activity that is called at runtime in an Android App. When the user clicks the back button the Activity is destroyed and I overrode the onSaveInstanceState
method to save outState
to be retrieved in a second time but onSaveInstanceState
is never called when the user clicks the back button.
Do you know why this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当用户按 BACK 时,不应调用
onSaveInstanceState()
。当用户更改配置(例如,旋转屏幕)时,如果 Android 认为 Activity 有被破坏的风险,但仍可在堆栈上访问,或者可能还有其他一些情况,它将被调用。
onSaveInstanceState()
is not supposed to be called when the user presses BACK.It will be called when the user changes configuration (e.g., rotates the screen), if Android believes that the activity is at risk of being destroyed while still being reachable on the stack, and perhaps a few other cases.