首页 > 作文

onSaveInstanceState onRestoreInstanceState 在生命周期里的顺序

更新时间:2023-04-04 02:50:51 阅读: 评论:0

12-09 22:57:13.727 D/Lifecycle: onCreate12-09 22:57:13.879 D/Lifecycle: onStart12-09 22:57:13.889 D/Lifecycle: onResume--------------- 旋转画面 -----------------------12-09 22:作文好句57:19.375 D/Lifecycle: onPau12-09 22:57:19.375 D/Lif阴处长痘痘ecycle: onSaveInstanceState  (有些文章说 onSaveInstanceState在onPau之后)12-09 22:57:19.379 D/Lifecycle: onStop12-09 22:57:19.379 D/Lifecycle: onDestroy12-09 22:57:19.434 D/Lifecycle: onCreate12-09 22:57:19.434 D/Lifecycle: onActivityResult12-09 22:57:19.434 D/Lifecycle: onReStart​​​​​12-09 22:57:19.507 D/Lifecycle: onStart12-09 22:57:19.508 D/Lifecycle: onRestoreInstanceState12-09 22:57:19.510 D/Li如何快速治疗咳嗽fecycle: onResume

如果画面有dialog,fragment,在onRestoreInstanceState之前show的话,由于还没有状态,show里面执行commit时会发生以下提示错误。

Caud by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState(编者:onSaveInstanceState之前实现commit的话,commit之后的状态就不被保存了。commit之后再onSaveInstanceState才能把frag状态保存下来)
//onResum之前show的逻辑,移到onResume里    /** 把显示逻辑保存下来 */    private var showFragmentsTask: (() -> Unit)? = null    override fun onActivityResult(requestCode: I快乐的暑假nt, resultCode: Int, data: Intent?) {        甘棠湖super.onActivityResult(requestCode, resultCode, data)       //when (requestCode) {       //    //show frag1处理       //    //show frag2处理       //}       把上面的处理放到变量里        showFragmentsTask = when (requestCode) {           //show frag1处理           //show frag2处理           el -> null        }    }    override fun onResumeFragments() {        super.onResumeFragments()        showFragmentsTask ?.invoke()        showFragmentsTask = null    }

参考

commitallowingstateloss 和commit的区别/d/file/titlepic/

onActivityResult 调用时机 https://kokufu.blogspot.com/2012/09/onactivityresult.html

错误回避方法https://kokufu.blogspot.com/2014/08/onactivityresult-dialogfragmentshow.html

本文地址:https://blog.csdn.net/vovo2000/article/details/107930230

本文发布于:2023-04-04 02:50:32,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/05884cf8cc366cab64b7d3defc00144f.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:onSaveInstanceState onRestoreInstanceState 在生命周期里的顺序.doc

本文 PDF 下载地址:onSaveInstanceState onRestoreInstanceState 在生命周期里的顺序.pdf

标签:状态   逻辑   画面   错误
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图