First, I believe this is the same issue as described by this SO post. I want to provide more details and be as specific as possible in the hope that some guru will come up with an elegant solution. This happens with Android 5.1
The following code
startActivityForResult(myMediaProjectionManager.createScreenCaptureIntent(), REQUEST_CODE_SCREEN_RECORDING);
will show the following prompt to the user:
If the user does not select "Don't show again", everything will work exactly as expected. Unfortunately, if "Don't show again" is selected, the same code will lead to the following prompt from the next run:
The device will go to the lock screen after the prompt.
Could anyone confirm this is caused by a system bug and offer a remedy without asking the user to avoid selecting "Don't show again"?