Android Marshmallow: Changing permissions at run time crashes app

前端 未结 3 1372
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 10:05

Marshmallow has redesigned getting permissions. So Handled permissions before calling the method which needs permissions and it works fine, but It crashes in the following s

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 11:06

    Observed that app gets created again, don't understand why this happens. Any suggestions to rectify this issue would be welcome!

    Because when permissions change, application "state" should be invalidated. The proper way to do that is destroy the root context, which is the application itself.

    You have to check the permissions granted status each time you query the API methods that require these permissions. You can't rely on some SharedPreferences flag indicating that "user granted the permissions in onboarding, ok, lets have fun". Make your app stateless in this regards.

    For example, you can create some BaseActivity/BaseFragment or Utility and move all the checking logic in there.

提交回复
热议问题