It is known that when we deny permissions at runtime in Android 6.0 and resume the app from the recent menu, the app process
You should put code to check the permission status in your onResume
callback. If the user is switching to the System settings permission activity, your Activity will get paused. If the user enables a permission and then returns to your Activity, then onResume
will be called, and you will have an opportunity to check for the new permission at that point. Then, you can do whatever you need to restart your activity, such as calling startActivity
with an Intent that has FLAG_ACTIVITY_NEW_TASK
and FLAG_ACTIVITY_CLEAR_TASK
and launches your Activity again.
override fun onResume() {
super.onResume()
// check for permission
checkPermissionsAndRestartIfNecessary()
}
private fun checkPermissionsAndRestartIfNecessary() {
if (ContextCompat.checkSelfPermission(...) {
...
}
}