Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Re-creating an Activity while changing the permissions at runtime in Android M or above

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?

like image 933
Polam Naganji Avatar asked Oct 25 '16 12:10

Polam Naganji


1 Answers

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.).

like image 140
CommonsWare Avatar answered Sep 28 '22 06:09

CommonsWare