Keep Screen On in Android

Solution 1: use PowerManager and WakeLock

In AndroidManifest.xml:

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

In your Activity:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
PowerManager.WakeLock mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); 
// in on
Resume() call

mWakeLock.acquire(); 
// in on
Pause() call 
mWakeLock.release();

Solution 2: use the window flag FLAG_KEEP_SCREEN_ON

Put the following code in your Activity’s onCreate method:

@Override 
protected void on
Create(Bundle icicle) { 
    super.on
Create(icicle);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
}

Reference