tags:

views:

129

answers:

1

Hi! I have found two ways on keeping the screen on:

First one is simpler:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Second one is using a wakelock and requiring an extra permission:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);  
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

Is there any real difference between this two methods apart from the second one being more complicated to implement and requiring an extra permission? Will the end result be always the same?

+2  A: 

You should see Coding for (Battery) Life Google IO presentation, slide 16

If you don't want to, then: You could do the first one in the XML for any layout element and it is the suggested one to use (don't know about applying it to the window though, might be as bad as the wakelock, dunno).

Roosmaa
Thanks, I didn't know about the xml way. I think it is almost equivalent to the window one. However in the presentation it says that wakelocks are costly if forgotten. So if done right they should be ok.It seems that the end result would be the same. I will choose the recommended way then.
janfsd