How to enable or disable autoload in android?

I have one toggle button that should enable and disable startup in the application, so how can we do this in app pls, help me here.

Thanks in advance.

+3
source share
3 answers

If with autolock you mean that the phone does not turn off the screen due to a period of inactivity, you can do the following:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

To stop the screen from "locking":

wl.acquire();

so that it blocks again:

wl.release();
+4
source

DO NOT use wakelocks. You can not let it go, and then you can drain the battery and annoy the user. And this requires additional permissions.

Instead, do it in onCreate ():

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+11
source

, , , .

Check out this site: PowerManager

0
source

Source: https://habr.com/ru/post/1786413/


All Articles