A long time did not write blog, and recently to achieve similar functions, each time Baidu to find is not very convenient, or in their own blog record a pen!
There are three types of methods:
1. Apply for a bright screen lock
PM = (PowerManager) context.getsystemservice (Context.power_service);
Get the Power Manager object
WL = Pm.newwakelock (Powermanager.acquire_causes_wakeup | Powermanager.full_wake_lock, "TEST");
Wl.acquire ();
Release when not in use
This thing is deep water, we need to take time to study, also including CPU wake lock and so on
2. Through the Flag property of window
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_ SCREEN_ON);
Setcontentview (r.layout.xmltext);//must be before this
This property is actually Google's alternative to Method 1.
3. Recommended use, this method is the simplest, no need to modify the code
Android:keepscreenon= "true"
As long as the control basically has this property, the code can also be set
Three ways Android keeps the screen solid