Android Keep The Screen On

You surely want to keep the screen of your phone ON and you don’t know how to do this, otherwise you wouldn’t be on our blog :P  But, you are on the right place, because in this tutorial I will show you how to keep the screen on programatically.

1. Create a new project and call your java class(the one that is generated by Eclipse or other IDE)“MyActivity”.
2. Go to MyActivity class and put the following code:

package com.example;

import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;

public class MyActivity extends Activity {

    private PowerManager.WakeLock mWakeLock;

    public void onCreate(Bundle savedInstanceState) {

        // this is how you can keep the screen ON and don't let the phone to lock
        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Tag");

    public void onDestroy() {

3. And the last step, put the following permission into the AndroidManifest.xml file:

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

So the AndroidManifest.xml file will look like this:

Scroll to Top