How to be notified when the screen turns off in Android 5.0 Lollipop?

I have an application that runs in the background and triggers an activity when a certain event occurs on the phone. I'm on Android 5.0, when the user has a screen pinned to another app, the call to startActivity (intent) is completely ignored. My app doesn't know the activity hasn't started, so the user won't have another chance to see the activity until they manually open my app.

Is there any event that I can register to be notified when the screen turns off so I can start my activity again?

+3


source to share


2 answers


Your app must be a device administrator (with administrator rights granted by the user). Once you have done that, you can implement this callback:

AdminReceiver.onLockTaskModeExiting(Context context, Intent intent)



do something when commit mode is stopped.

To see how to make an app an administrator: you can check one of my previous answers here

+1


source


Here is a method in the ActivityManager class that reports the status of the current task if it is locked or not in the case of screen binding:

!mActivityManager.isInLockTaskMode()

      



Check this link for more information: http://developer.android.com/reference/android/app/ActivityManager.html#isInLockTaskMode%28%29

+1


source







All Articles