简体   繁体   English

活动销毁后,savedInstanceState始终为null

[英]savedInstanceState is always null after activity gets destroyed

I've got parent and child activities. 我有家长和孩子的活动。 Parent activity stores custom state in onSaveInstanceState (super.onSaveInstanceState is called after all needed items are packed into bundle) and then the state is read in onCreate however savedInstanceState is always null for some reason. 父活动将自定义状态存储在onSaveInstanceState中(将所有需要的项目打包到包中后将调用super.onSaveInstanceState),然后在onCreate中读取该状态,但是由于某种原因,saveInstanceState始终为null。

Here is sequence of logged events on parent activity: onPause->onSaveInstanceState->onStop. 这是父活动上已记录事件的顺序:onPause-> onSaveInstanceState-> onStop。 Then child activity gets shown and when I press Up, parent activity fires onDestroy, then onCreate with null savedInstanceState. 然后显示子活动,当我按Up时,父活动将触发onDestroy,然后触发具有空saveInstanceState的onCreate。

I'm kind of out of ideas on the matter - please advise what I might be missing. 我对此事有点想法-请告知我可能会错过的内容。

Thanks. 谢谢。

I am facing the same issue. 我正面临着同样的问题。 My solution is change ParentActivity launch mode in manifest from default to 我的解决方案是将ParentActivity启动模式从默认更改为

android:launchMode="singleTop"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM