Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable sleep on certain activity

Tags:

android

sleep

Is there any way to disable sleep of android mobile phone when user is in certain activity.

I want to disable screen time out when user is in main activity.

Is there any way to do it? Don't know if it is possible or not?

like image 422
Amrit Sharma Avatar asked Nov 03 '12 13:11

Amrit Sharma


3 Answers

Try this.

 @Override
 protected void onCreate(Bundle icicle) 
 {
     super.onCreate(icicle);
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 }
like image 166
Chirag Avatar answered Oct 22 '22 01:10

Chirag


I am using this:

@Override
protected void onCreate(Bundle icicle) 
{
      super.onCreate(icicle);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

Don't forget to place the permission in the manifest

<uses-permission android:name="android.permission.WAKE_LOCK" />
like image 34
Ronald Coarite Avatar answered Oct 22 '22 02:10

Ronald Coarite


Best way just add

android:keepScreenOn="true"

to the parent layout of that activity.

like image 5
Anuraag Patil Avatar answered Oct 22 '22 02:10

Anuraag Patil