简体   繁体   English

Android在恢复焦点后无法正确恢复小部件

[英]Android not restoring widgets correctly upon restoring focus

I'm developing a rather GUI heavy android app and it has lots of little widgets (text fields, buttons etc..) which are dynamically configured at runtime. 我正在开发一个GUI繁重的android应用程序,它有许多小部件(文本字段,按钮等),这些小部件在运行时动态配置。 Everything is working well enough when the application has focus however once the user pushes the app to the background and restore it, all the widgets lose their dynamic state and revert back to their default state defined by their layout. 当应用程序具有焦点时,一切工作都很好,但是一旦用户将应用程序推到后台并还原它,所有小部件都将失去其动态状态并恢复为其布局定义的默认状态。 Is this the proper behavior of Android apps? 这是Android应用程序的正确行为吗?

I've developed numerous UIs on other platforms (iOS, Windows, Mac) and I've never seen behavior like this.. Do i have to do some magic dance to make Android keep the widgets state between re-focus? 我在其他平台(iOS,Windows,Mac)上开发了许多UI,但从未见过这样的行为。我是否需要做一些魔术舞来使Android保持小部件在重新聚焦之间的状态? Any tips would be appreciated thanks! 任何提示将不胜感激,谢谢!

What you need to do is to look at the lifecycle of an activity . 您需要做的是查看活动的生命周期

Basically, you need to save state in an onPause() function, and restore it with an onResume() function. 基本上,您需要将状态保存在onPause()函数中,并使用onResume()函数将其还原。

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

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