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?
Try this.
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
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" />
Best way just add
android:keepScreenOn="true"
to the parent layout of that activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With