Flutter app 安卓iOS前后台切换监听
class _MyAppState extends State with WidgetsBindingObserver { @overrideinitState() { WidgetsBinding.instance.addObserver(this); } @override void didChangeAppLifecycleState(AppLifecycleState state) {print("--"+ state.toString()); switch (state) {caseAppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。break;caseAppLifecycleState.resumed: // 应用程序可见,前台break;caseAppLifecycleState.paused: // 应用程序不可见,后台setHomeAppIcon();break;caseAppLifecycleState.suspending: // 申请将暂时暂停break; } } @override voiddispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); }复制代码
喜欢可以加群号:913934649
更多详解:
网友评论