安卓:Wakelock和放大器;处理方向变化 [英] Android: Wakelock & handling orientation change

查看:139
本文介绍了安卓:Wakelock和放大器;处理方向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Wakelock在我的应用程序,以prevent手机进入睡眠状态时,该应用程序是可见的。

I'm using Wakelock in my application to prevent the phone from sleeping when the app is visible.

在问题出现时,有一个方向变化,系统破坏并重新创建在横向模式下的应用程序。如果wakelock计时器在背景已经过期系统占用wakelock的释放为契机,切换在屏幕上。

The problem comes when there is an orientation change and the system destroys and re-creates the app in landscape mode. If the wakelock timer has expired in the background the system takes the release of wakelock as an opportunity to switch off the screen.

编辑:我要指出,我设置Wakelock onResume,和释放的onPause - 据我所知,有必要从泄漏wakelock然后释放到prevent应用程序

I should mention that I am setting Wakelock onResume, and releasing onPause - as I understand it, it's necessary to release then to prevent the app from leaking the wakelock.

我需要wakelock继续通过方向变化。

I need wakelock to continue through the orientation change.

在下面,我提出了一个解决这个。这是preferred的方法来处理它,还有什么办法?

Below I've outlined a solution to this. Is this the preferred way to handle it, and are there any alternatives?

创建持有wakelock(而非活性)一个服务,当活动解除绑定服务启动一个倒计时器(用于说10秒),其中,当定时器期满,如果活动不重新绑定它将释放wakelock。如果这是一个简单的方向变化的活动将是在10秒内重新绑定,因此维持wakelock,如果没有,wakelock将被释放。

Create a service which holds wakelock (rather than the activity) and when the activity unbinds the service starts a countdown timer (for say 10 seconds) in which it will release wakelock when the timer expires if the activity does not rebind. If it was a simple orientation change the activity will rebind within that 10 seconds and so maintain wakelock, if it doesn't, wakelock will be released.

感谢。

推荐答案

而不是一个 WakeLock ,试试 getWindow()。setFlags()使用 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 标记。

Instead of a WakeLock, try getWindow().setFlags() using the WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON flag.

如果该wakelock计时器已过期   该系统采用了后台   wakelock的发布为契机,   关掉屏幕

If the wakelock timer has expired in the background the system takes the release of wakelock as an opportunity to switch off the screen.

这不应该。根据定义,用户已与之交互的设备,所以在屏幕应该停留在这一原因,独立的别的

It shouldn't. By definition, the user has interacted with the device, so the screen should stay on for that reason, independent of anything else.

这篇关于安卓:Wakelock和放大器;处理方向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆