I'm trying to exit the app by pressing the back button on Android. Pre Android 12, my MainActivity.onDestroy
gets called but with Android 12.0, it's not getting called.
CodePudding user response:
Make sure your MainActivity
extends FlutterActivity
and not FlutterFragmentActivity
as with Android 12, the later's onDestroy
won't get called. So:
Works for all Android versions:
class MainActivity extends FlutterActivity {}
Works for Android < 12.
class MainActivity extends FlutterFragmentActivity {}
CodePudding user response:
Please refer below code
FlatButton(
child: new Text("Exit",
),
onPressed: () {
(Platform.isIOS) ? exit(0) : SystemNavigator.pop();
},
),