之前关闭屏幕就太晚了
我有一个活动,在其 onPause 上必须做一些工作,但在屏幕关闭时则不需要。 我已经为 ACTION_SCREEN_OFF
意图注册了接收器,理论上,这个和应用程序级别的静态标志应该可以解决问题,但是......它不起作用,因为 onPause< /code> 在接收者获取其 Intent 之前调用活动的回调。 也就是说:logcat*ting* 当按下空闲按钮时,我可以首先看到
onPause
跟踪,然后看到 onReceive
跟踪。 此时,设置静态标志并不是很重要...
是否有可能在 Activity 的 onPause 时间知道屏幕已关闭?
提前致谢
L。
I've an activity that, on its onPause has to do some work but not when the screen is turned off.
I've already registered the receiver for the ACTION_SCREEN_OFF
intent and, theoretically, this and a static flag at application level should do the trick but... It doesn't work because the onPause
callback on the activity is invoked BEFORE the receiver can get its Intent.
That is: logcat*ting* while push down the idle button, i can see the onPause
trace first and the onReceive
after.
At this point, setting up the static flag is not very important...
Any possibilities to know at activity's onPause
time that the screen has turned off?
Thanks in advance
L.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出路
我遇到了同样的问题,接收器不是Android 开发人员的
http: //developer.android.com/reference/android/content/BroadcastReceiver.html
“注意:如果在 Activity.onResume() 实现中注册接收器,则应在 Activity.onPause() 中取消注册它。(您暂停时不会接收意图,这将减少不必要的系统开销)不要在 Activity.onSaveInstanceState() 中取消注册,因为如果用户在历史堆栈中移回,则不会调用此方法。”
相反,在 onPause 方法中创建一个电源管理器[我从这个链接得到它]
如何查看 Android 设备的屏幕状态?
I had the same problem and a receiver is not the way to go
android developer
http://developer.android.com/reference/android/content/BroadcastReceiver.html
"Note: If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won't receive intents when paused, and this will cut down on unnecessary system overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back in the history stack."
Instead create a power manager in your onPause method [I got it from this link]
how to find out screen status on an android device?