Seth Hikari Seth Hikari - 1 year ago 95
Android Question

How do I keep the screen on in my App?

For my Android app I never want the phone to lock or the back light to turn off

Answer Source

Use PowerManager.WakeLock class inorder to perform this. See the following code:

import android.os.PowerManager;

public class MyActivity extends Activity {

    protected PowerManager.WakeLock mWakeLock;

    /** Called when the activity is first created. */
    public void onCreate(final Bundle icicle) {

        /* This code together with the one in onDestroy() 
         * will make the screen be always on until this Activity gets destroyed. */
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");

    public void onDestroy() {

Use the follwing permission in manifest file :

<uses-permission android:name="android.permission.WAKE_LOCK" />

Hope this will solve your problem...:)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download