简体   繁体   English

Flutter 应用程序在恢复后显示主屏幕

[英]Flutter application showing Home screen after resuming

I am developing a flutter application.我正在开发一个 flutter 应用程序。 Inside app, a screen contain Forms that is to be filled by user.在应用程序内部,一个屏幕包含由用户填写的 Forms。 But while filling the fields, if the app minimized and opened after a minute (approximately), I am not able to see the same screen.但是在填写字段时,如果应用程序最小化并在一分钟(大约)后打开,我将无法看到相同的屏幕。 Instead app showing homescreen and I am losing the data filled up to then.而是显示主屏幕的应用程序,我正在丢失填充的数据。 Is there any solution to make app remembers the screen before pausing and showing same screen without loosing data on resume?是否有任何解决方案可以让应用在暂停和显示同一屏幕之前记住屏幕,而不会丢失恢复数据? Thanks in advance.提前致谢。

According to the Android documentation :根据Android 文档

In this scenario, your app is placed in the background the system does its best to keep your app process in memory.在这种情况下,您的应用程序被放置在后台,系统会尽力将您的应用程序进程保持在 memory 中。 However, the system may destroy the application process while the user is away interacting with other apps.但是,当用户离开与其他应用程序交互时,系统可能会破坏应用程序进程。 In such a case, the activity instance is destroyed, along with any state stored in it.在这种情况下,活动实例连同其中存储的任何 state 都会被销毁。 When the user relaunches the app, the activity is unexpectedly in a clean state.当用户重新启动应用程序时,活动意外地位于干净的 state 中。 To learn more about process death, see Processes and Application Lifecycle .要了解有关进程死亡的更多信息,请参阅进程和应用程序生命周期

Therefore the most "safe" way would be to store your app state in a JSON file and restore it from the JSON file on start of the app.因此,最“安全”的方法是将您的应用程序 state 存储在 JSON 文件中,并在应用程序启动时从 JSON 文件中恢复它。 If the app is gracefully stopped you persist the state in the JSON file or delete the JSON file if no state should be stored. If the app is gracefully stopped you persist the state in the JSON file or delete the JSON file if no state should be stored.

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

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