对于setKeepScreenOn / FLAG_KEEP_SCREEN_ON正确的方法 [英] Correct method for setKeepScreenOn / FLAG_KEEP_SCREEN_ON

查看:1820
本文介绍了对于setKeepScreenOn / FLAG_KEEP_SCREEN_ON正确的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的方法setKeepScreenOn(真),并一直无法弄清楚如何调用这与当前活动(其中有一个内容视图集)。我已经能够得到它在我的按钮,它们总是$在视点P $ psent一条要求它的工作,但这种感觉错了 - 我敢肯定,必须有一个办法来解决这个问题。我想引用当前的重点是这样的:

I am using the method setKeepScreenOn(true) and haven't been able to figure out how to call this in relation to the current Activity (which has a content view set). I've been able to get it to work by calling it on one of my buttons which is always present in the view, but this feels wrong - and I'm sure there must be a way to get around this. I tried referencing the current focus like this:

getCurrentFocus().setKeepScreenOn(true);

但抛出一个NullPointerException异常。也许没有目前的工作重点。 那么,谁能告诉我怎么可以参考我在工作里面的视图类?感谢:)

but that threw a NullPointerException. Maybe there was no current focus. So, can anyone tell me how I can reference the view class which I am working inside? Thanks :)

推荐答案

尝试<一href="http://stackoverflow.com/questions/3949917/how-to-keep-android-device-from-sleeping-while-plugged-in/3951855#3951855">this回答:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

getWindow 是活动定义的方法,而不会要求你找到一个查看第一。

getWindow is a method defined for activities, and won't require you to find a View first.

这篇关于对于setKeepScreenOn / FLAG_KEEP_SCREEN_ON正确的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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