![](/img/trans.png)
[英]StreamSubscription not resuming when the app comes back to foreground
[英]Flutter Capture event when app comes to Foreground from triggered Intent
我試圖在這里完成一些基本的東西。 場景:我正在使用isLocationServiceEnabled
檢查init()
上的 GPS 狀態。 如果 GPS 關閉,我將顯示一個使用AndroidIntent
重定向到位置設置的彈出窗口。 如果在不打開 GPS 的情況下進行回擊,我想在我的應用程序進入前台時捕獲該事件。 我猜它與生命周期有關,並嘗試如下,控制台上沒有打印任何內容
AppLifecycleState _notification;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_notification = state;
print('onResumed called 1');
print(_notification);
});
if( state == AppLifecycleState.resumed){
print('onResumed called 2');
}
}
我在這里錯過了什么嗎?
您是否像這樣使用WidgetsBindingObserver
擴展 class :
class _WhateverWidget extends State<WhateverWidget> with WidgetsBindingObserver
然后像這樣初始化一個實例:
@override void initState() {
WidgetsBinding.instance.addObserver(this);
super.initState();
}
@override void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.