6

I know, with Android Marshmallow, we have to ask permissions every time we need a functionality that require a permission.

I do this for new App, but for old BIG App is more complicated.

For old BIG App, I ask all permissions in "MainActivity".

So, my app is started and shows a Map Fragment. I ask for Location Permission with no problem. The user agrees.

The user puts it in background, goes in the App Settings and denies permission. Then he puts the App in foreground: App crashes!!

I know, there is a problem using Map Fragment.

But the App is too BIG to analyze every single permission.

I need the FAST solution: PERMISSION CHANGE ---> RESTART APP!!!

And this is what GoogleMaps does!

I started GoogleMaps, and put it in background.

GoogleMaps App permissions, the first difference:

in my App, if I denied a permission, I haven't this message showing for Google Maps:

Permission denied

After that, if I put GoogleMaps in foreground, the App restart with no problem:

GoogleMaps restart

I need this for my app. Can someone help me?!?!?!?

Thanks a lot!!

  • check the permission in onResume() method, to be sure that it's granted, if not, just start your launch activity with clearTop flag – Viktor Yakunin Nov 18 '15 at 16:21
  • @ViktorYakunin I know, but this seems I do for all my activities.... For this, I wrote "FAST" (less code) solution :-) And If I have 20 permissions, I have to check in every Activities, called everytime the system call onResume() 8-) – Michele Saccomanno Nov 18 '15 at 17:56
  • Try this it may be work http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Jan 03 '17 at 10:44
  • Try this it may be work http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Jan 03 '17 at 10:47

1 Answers1

9

When permissions are revoked, your app is killed and restarted. Look on the logcat when you revoke permission with your application in background. You will see : I/ActivityManager(572): Killing 13896:com.your.app/uxxxx (): permissions revoked So you need to only check permissions in your class "myApplication extends Application" in the onCreate() function.

earlypearl
  • 596
  • 6
  • 10
  • 1
    I have: I/ActivityManager(572): Killing 13896:com.my.app...... but this doesn't restart the app. Only Activity restart – Michele Saccomanno Nov 19 '15 at 11:37
  • 3
    What about when a permission is granted? I am in the same boat, but Android is not restarting the application if a permission is granted through the settings screen. – lostintranslation Dec 15 '15 at 18:24
  • 17
    Is anyone able to find within the documentation that this is the expected behaviour? I understand why the app restarts when a granted permission is denied but i just cannot for the life of me find it documented anywhere? – Joe Maher Apr 17 '16 at 02:56