2019-11-08
Turn off light after 30 second of inactivity [on hold]
stackoverflow
Question

My app is set LCD always on but it loses too much power, I want to dim or turn off LCD light(no sleep or lock) after 50 seconds of inactivity.

I tried some solutions but no one cant cures my problem.

I just want it on one activity, not others.

Please help me with any class or method that I can use for this

Edited:

My main problem:

I want to use hard key of an android device when it locked.

So now tell me,How can i use a hard key as a click in my app when screen locked???

Edit:

i have a device with 5 hard key and i want use them when device locked down.

Answer
1

Keeping the screen on forever is as simple as creating a wakeLock. Turning off the screen after sometimes (probably 30 seconds or so) will be enabled by default in almost all the Android devices.

I think what you are looking for here is an app that behaves like a media player app/ music playing app. You can do so by running a service in the foreground. You will need to create a persistent notification for this. This way, your app/ activity will not get killed even if the device screen is off.

Find the documentation here: https://developer.android.com/guide/components/services#Foreground

EDIT #1 As discussed in the comments, this link was helpful to the OP for getting the answer to his query: https://stackoverflow.com/a/29818026/3811983

Turn off light after 30 second of inactivity [on hold]
See more ...