如何在didChangeAppLifecycleState(iOS和android设备)上完全重新启动颤振应用程序

如何在didChangeAppLifecycleState(iOS和android设备)上完全重新启动颤振应用程序,android,ios,flutter,dart,Android,Ios,Flutter,Dart,我有一个应用程序,当AppLifeCycleState处于暂停状态时,我想完全重新启动该应用程序 这似乎适用于android(Pixel 3 XL Api 28),但不适用于iOS设备 与本机iOS等效: 在我的应用程序的本机iOS版本上,我在AppDelegate中的ApplicationIdentinterBackground函数中运行了退出(0) 我已尝试使用WidgetBindingObserver使MyApp有状态,并监听状态的更改。在.paused状态下,我尝试执行exit(0)和S

我有一个应用程序,当
AppLifeCycleState
处于
暂停状态时,我想完全重新启动该应用程序

这似乎适用于android(Pixel 3 XL Api 28)
,但不适用于iOS设备

与本机iOS等效: 在我的应用程序的本机iOS版本上,我在AppDelegate中的ApplicationIdentinterBackground函数中运行了退出(0)

我已尝试使用
WidgetBindingObserver
使MyApp有状态,并监听状态的更改。在.paused状态下,我尝试执行
exit(0)
SystemChannels.platform.invokeMethod('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;
    }
  }
@覆盖
void initState(){
super.initState();
WidgetsBinding.instance.addObserver(这个);
}
@凌驾
无效处置(){
super.dispose();
WidgetsBinding.instance.removeObserver(此);
}
@凌驾
void didchangeAppifecyclestate(AppLifecycleState状态){
super.didChangeAppLifecycleState(州);
开关(状态){
案例AppLifecycleState.paused:
打印(“暂停状态”);
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
//我还尝试了退出(0);此处。
打破
案例AppLifecycleState.resumed:
打印(“恢复状态”);
打破
案例AppLifecycleState.inactive:
打印(“非活动状态”);
打破
案例AppLifecycleState.suspending:
打印(“挂起状态”);
打破
}
}
我希望应用程序会退出,然后再次打开时会重新启动,但它根本不会退出。它只是恢复到进入暂停状态之前的状态。这种行为仅在iOS设备上发生


我知道我的代码不是一个完全有效的最小示例-如果您需要我为大家创建一个示例,请告诉我。

好的,所以我已经解决了这个问题,但我不能100%确定以前使用
退出(0)
的尝试为什么不起作用

我已将
didChangeAppLifecycleState
函数更改为以下内容

@override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.paused:
        print('paused state');
        SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop');
        if (Platform.isIOS) {
          exit(0);
        }
        break;
      case AppLifecycleState.resumed:
        print('resumed state');
        break;
      case AppLifecycleState.inactive:
        print('inactive state');
        break;
      case AppLifecycleState.suspending:
        print('suspending state');
        break;
    }
  }

如果有人能解释为什么仅仅使用
exit(0)
本身不起作用,我希望能更好地理解这一点。

好的,所以我已经解决了这个问题,但我不能100%确定为什么以前使用
exit(0)
的尝试不起作用

我已将
didChangeAppLifecycleState
函数更改为以下内容

@override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.paused:
        print('paused state');
        SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop');
        if (Platform.isIOS) {
          exit(0);
        }
        break;
      case AppLifecycleState.resumed:
        print('resumed state');
        break;
      case AppLifecycleState.inactive:
        print('inactive state');
        break;
      case AppLifecycleState.suspending:
        print('suspending state');
        break;
    }
  }
如果有人能解释为什么仅仅使用
exit(0)
本身不起作用,我希望能更好地理解这一点