My app uses location permission. If this permission is revoked at runtime from App Settings and coming back to app, the current activity is destroyed and recreated. How to prevent the recreation of that activity?
You can't. If the user revokes a permission from your app, Android terminates your process. This forces you to go back through your check-for-the-permission code, where you will find out that you lost the permission.
Since your app's process can be terminated at any point when your UI is not in the foreground, your app should already be able to handle this case. If it cannot, then you need to fix that, as your process will be terminated for other reasons while it is in the background (OS freeing up system RAM, user using a task-killer app, user pressing Force Stop in Settings, etc.).
That is the straightforward cleanup mechanism implemented in android to handle the change in permissions in android M.
The process gets terminated and on coming live, init's
itself with the available permissions.
So, the answer to your query -> you cant prevent recreation of your activity as the whole process is restarted. At max if you still wish to detect such an event, you could persist some flag before revoking permission and check it after your app comes into foreground.
© 2022 - 2024 — McMap. All rights reserved.