How to Restart the app in android marshmallow when

2019-06-12 10:46发布

问题:

I have an android application which was supporting till lollipop. Now I'm migrating it to support Marshmallow.

I am stuck in a case where if we manually changed the app permission in marshmallow it kills all the process.

I get it as explained by @CommonsWare in similar question here.

But in my case I have to kill the app and need to restart the app. Because my app each activity is dependent on previous activity some data is shared. I just need to know when we manually change the permission is there a way our app get noticed.?

I meant any callback occurs. if Not is there anyway I can handle this case.? Please Let me know if the question is too broad I'll update my question

Thanks in advance

回答1:

I just need to know when we manually change the permission is there a way our app get noticed.?

Your process is terminated. This is indistinguishable from any other reason why your process might be terminated.

I meant any callback occurs.

No. You get ordinary lifecycle callbacks (e.g., onPause(), onStop()) as the user navigates over to Settings to be able to revoke the permission, but that's it. There is no specific callback related to losing the permission.

Also note that the user could leave your app, your process could be terminated for other reasons, the user could then go into Settings and revoke your permission, then the user could return to your app. If all of that happens within ~30 minutes, Android will still try to rebuild the outstanding task. You certainly would not get a callback of any sort in this case, as your process was not running before the permission was revoked, let alone after.