【发布时间】:2019-07-26 12:34:08
【问题描述】:
当AppLifeCycleState 为.paused 时,我想完全重启一个应用程序
这似乎适用于 android (Pixel 3 XL Api 28),但不适用于 iOS 设备。
原生 iOS 等效项:
在我的原生 iOS 版本的应用中,我在 AppDelegate 的 applicationDidEnterBackground 函数中运行了 exit(0)。
我尝试使用 WidgetBindingObserver 使 MyApp 有状态并监听状态的变化。在 .paused 状态下,我尝试执行 exit(0) 和 SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop');
MyApp的状态
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.paused:
print('paused state');
SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop');
//I have also tried exit(0); here.
break;
case AppLifecycleState.resumed:
print('resumed state');
break;
case AppLifecycleState.inactive:
print('inactive state');
break;
case AppLifecycleState.suspending:
print('suspending state');
break;
}
}
我预计应用程序会退出,然后在再次打开时会重新启动,但它根本不会退出。它只是恢复到进入暂停状态之前的位置。此行为仅适用于 iOS 设备。
我知道我的代码不是一个完整的最小示例 - 如果您需要我设置一个示例供人们尝试,请告诉我。
【问题讨论】: