First step: Add Permissions First:
<uses-permission android:name= "Android.permission.WAKE_LOCK" ></uses-permission>
The second step: the code is implemented as follows:
public class Screenactivity extends Activity { PowerManager powermanager = null; WakeLock WakeLock = null; @Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); This.setcontentview (r.layout.main); PowerManager = (PowerManager) This.getsystemservice (this. Power_service); WakeLock = This.powerManager.newWakeLock (Powermanager.full_wake_lock, "My LOCK"); } @Override protected void Onresume () { super.onresume (); Wakelock.acquire (); } @Override protected void OnPause () { super.onpause (); Wakelock.release (); } }
The last note: calling the Wakelock function in a different life cycle can make the system run normally (if the activity ends without calling wakelock.release, the screen will always be solid).