Activity restart every time when disable permission from setting

限于喜欢 提交于 2019-12-01 06:23:31

When you revoke permissions from app settings - Activity restarts and all it's components too. But in onCreate(...) savedInstanceState doesn't equal to null.

Thus you can use such hack:

if (savedInstanceState != null) {

}

Using the above hack app resume last fragmentC.

This is something normal and expected in AOSP. Android kills the app process while saving all states and fragments in FragmentManager, so you should retrieve back your fragment from the FragmentManager you were commiting tour fragments to. See an example approach:

// Try to retrieve fragment from fragment manager
ExampleFragment exampleFragment = (ExampleFragment) getSupportFragmentManager().findFragmentByTag("ExampleFragment");
// Fragment was not saved in fragment manager, create a new instance
if (exampleFragment == null) exampleFragment = ExampleFragment.newInstance();

Note that I'm using getSupportFragmentManager() as an example here (in the activity) but you have to use getChildFragmentManager() within fragments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!