AppLifecycleState 会在整个应用程序生命周期或我使用它的页面中处于活动状态吗
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
debugPrint("AppLifecycleState.resumed");
} else if (state == AppLifecycleState.paused) {
debugPrint("AppLifecycleState.paused");
} else if (state == AppLifecycleState.detached) {
debugPrint("AppLifecycleState.detached");
} else if (state == AppLifecycleState.inactive) {
debugPrint("AppLifecycleState.inactive");
}
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold();
}
这是上面的演示页面,我想知道 didChangeAppLifecycleState() 方法是否会在我更改应用程序状态时打印,或者仅在我从演示页更改应用程序状态时打印
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
debugPrint("AppLifecycleState.resumed");
} else if (state == AppLifecycleState.paused) {
debugPrint("AppLifecycleState.paused");
} else if (state == AppLifecycleState.detached) {
debugPrint("AppLifecycleState.detached");
} else if (state == AppLifecycleState.inactive) {
debugPrint("AppLifecycleState.inactive");
}
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold();
}
this is a demoPage above,I wonder if the didChangeAppLifecycleState() method will print on any time I change app state,or just print when I change app state from DemoPage
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论