简体   繁体   English

Flutter打开/关闭设置导致main()再次运行

[英]Flutter Opening/Closing settings causes main() to be run again

I have an app that needs location to be turned on, so I've got something to open the location settings for them (testing on Android), so they can enable it, this works fine. 我有一个需要打开位置的应用程序,因此我有一些东西可以为他们打开位置设置(在Android上测试),以便他们可以启用它,这很好。

However, every time the settings are viewed and then closed (either via my app, or via just navigating to settings), I note in the app, main() seems to be called again (and hence all the various initStates and class variables etc are reset). 但是,每次查看设置然后将其关闭(通过我的应用程序或仅通过导航到设置)时,我注意到在应用程序中,main()似乎再次被调用(因此,所有各种initStates和类变量等重置)。 So all the previous state is lost including whether I've displayed a location dialog already, as I don't want to repeat opening the settings dialog if they've discarded it. 因此,所有以前的状态都会丢失,包括是否已经显示位置对话框,因为如果他们丢弃了设置对话框,我不想重复打开。

Is this normal Android behaviour, to reset an app when a settings dialog is displayed ? 这是正常的Android行为,可在显示设置对话框时重置应用程序? If so, is there anything simple that can be used that persists data across this ? 如果是这样,是否有任何简单的方法可用于在此过程中持久化数据?

The Android Developer settings have a toggle for Don't Keep Activities that can be set to simulate activities being closed early. Android Developer设置中有一个“ Don't Keep Activities开关,可以将其设置为模拟提前关闭的活动。 If it is set, your activity will be closed as soon as you close your app. 如果已设置,则关闭应用程序后,活动将立即关闭。

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

相关问题 关闭并再次打开后,SearchView中的查询丢失 - Query in a SearchView is lost after closing and opening it again 当我点击按钮时导航屏幕打开,但当我再次点击它时它不会再次关闭 - navigation Screen opening when i click on button but its not closing again when i click it again 即使关闭应用程序后也保存数据并查看,再次打开时不要加载数据并再次查看 - Save data and view even after closing application and when opening it again don't load data and view again 如何配置 Flutter 的 showModalBottomSheet 打开/关闭动画? - How do I configure Flutter's showModalBottomSheet opening/closing animation? Flutter-更改打开(白色)和关闭(红色)的动画图标颜色 - Flutter- Change animated icon color for opening(white) and closing(red) Flutter 返回 Main.dart 屏幕而不是关闭应用程序 - Flutter returns Main.dart screen instead of closing the Application 关闭对话框后再次打开对话框时,应用程序崩溃并给出“ java.lang.IllegalStateException” - App crashing giving 'java.lang.IllegalStateException' when opening a dialog again after closing it 以编程方式关闭设置 - Closing settings programmatically 打开和关闭SqliteDatabase - opening and closing SqliteDatabase 手电筒(手电筒)打开但没有关闭 - Flashlight (Torch) is opening but not closing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM