gpt4 book ai didi

安卓 :Why the Activity is in onPause?

转载 作者:行者123 更新时间:2023-11-29 16:15:40 25 4
gpt4 key购买 nike

我必须知道我的 Activity 是否显示。我会使用 onPause 和 onResume 方法,但我也想知道为什么 Activity 处于 onPause ....有3种情况:

  1. 由于显示器关闭而处于 onPause 状态
  2. onPause 中的 Activity ,因为用户单击了主页按钮
  3. onPause 中的 Activity,因为用户单击了主页按钮并关闭了屏幕

我该怎么办?谢谢

编辑:我用这段代码解决了:

ActivityManager activityManager = (ActivityManager)getContext().                .getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTasks = activityManager.getRunningTasks(Integer.MAX_VALUE));

最佳答案

*1.* 在 onPause 中的 Activity ,因为显示关闭并且如果出现任何调用:onPause() 调用

*2.*onPause 中的 Activity ,因为用户单击了主页按钮:onUserLeaveHint()onPause( ) 如果用户按下主页按钮

*3.*当用户按下返回键时:onUserInteraction() 在 onPause() 之前调用

关于安卓 :Why the Activity is in onPause?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9801031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com