简体   繁体   English

暂停后如何保存View的状态?

[英]How to save View's state after pause?

When my app completes some async tasks, it notifies UI about it. 当我的应用程序完成一些异步任务时,它会通知UI。

For example: 例如:

  1. user clicks on "Do work" button inside of my application -> async work started 用户单击我的应用程序内的“完成工作”按钮-> async work started
  2. and switches to another app -> state is saved 并切换到另一个应用程序-> state is saved
  3. then "work" inside my app is finished and View-s updated -> async work finished (note that my activity is paused) 然后我的应用程序中的“工作”完成,并且View-s更新-> async work finished (请注意,我的活动已暂停)
  4. User rotates the phone and then navigating back to my app 用户旋转手机,然后导航回我的应用
  5. problem: state is restored and View's state updated in 3 step is gone while work was finished! 问题:工作完成后, state is restored ,视图的状态在3步中更新了!

How to deal with such cases? 如何处理此类案件? Is there any way to save settings after app is paused? 应用暂停后,有什么方法可以保存设置?

考虑使用MvpQueuingBasePresenter或Model-View-Intent,它可以更好地处理与生命周期相关的事情。

I think you should update the state of the view in onResume method from that activity. 我认为您应该从该活动的onResume方法中更新视图的状态。

ref: https://developer.android.com/guide/components/activities/activity-lifecycle.html 参考: https : //developer.android.com/guide/components/activities/activity-lifecycle.html

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

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