What happens while we change permission manually from outside app in Android

Viewed 876

Recently I faced an issue while changing permission manually from outside of the app when the app is in background. This leads to error and loses it's state.

I searched S/O for the perfect strategy to face this issue but couldn't find rich answer about this. Some saying that the process is being recreated.

Can anybody enlighten me about this issue?

I want to know exactly what happens in this scenario and how to persist state and data while user changes permission manually and comes back to the app.

Thanks.

3 Answers

If your app needs a permission while it is running, depend on wich permission and where it is used, it will crash if manually revoke the permission because the app needs the granted permission. You can check the permission any where it is used to prevent crash.

When permissions are manually removed from android app settings, and then if during app's execution the permissions checks are not handled properly then app will crash.

While accessing features which requires permissions, you should create a single entry point for that each feature to launch in your code where you first check if the permission is granted or not and depending on the outcome access that feature or again prompt for the permission.

Recently I faced an issue while changing permission manually from outside of the app when the app is in background. This leads to error and loses it's state.

What was the issue and what error did you faced? Next- for loss of state - what state was lost? did you lost the data which you saved in Shared preference or something else?

I searched S/O for the perfect strategy to face this issue but couldn't find rich answer about this. Some saying that the process is being recreated.

Well the recommended approach from the official Android documentation for these kind of scenarios is very simple -

you'll have to test your app under a wider range of conditions.

Prior to Android 6.0, you could reasonably assume that if your app is running at all, it has all the permissions it declares in the app manifest. Beginning with Android 6.0 the user can turn permissions on or off for any app. You should test to ensure your app functions correctly whether or not it has any permissions.

Long story short - Test the app thoroughly - with special attention on
1. your app’s current permissions and the related code paths &
2. user flows across permission-protected services and data.

Related