How can I prevent Android from automatically locking when the activity (application) is in focus?

I am new to Android development. How can I prevent Android blocking when my application is in focus? When my application is out of focus, I want to guarantee that android os will have its default behavior.

+4
source share
2 answers

use

WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

you can do it using

Activity.getWindow (). AddFlags ().

+9
source
private PowerManager mPowerManager; private WakeLock mWakeLock; Write this in OnCreate // Get an instance of the PowerManager mPowerManager = (PowerManager) getSystemService(POWER_SERVICE); // Create a bright wake lock mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK| PowerManager.ACQUIRE_CAUSES_WAKEUP, getClass() .getName()); Write this in onResume mWakeLock.acquire(); write this in onPause mWakeLock.release(); 
0
source

All Articles