问题描述
我正在开发具有以下结构的android应用程序:MainActivity-> FragmentA-> FragmentB-> Fragment C
I am developing an android app with structure: MainActivity->FragmentA->FragmentB->Fragment C
现在在片段C中,我转到权限设置",然后将摄像机"的访问权限设置为拒绝",然后返回一个应用程序.我意识到该应用已重新启动(转换为片段A).愿您给我任何理由和建议来解决它.
Now in Fragment C, I go to Permission Setting and make access Camera to Deny, then I return an App. I realize that app restarted (transit to Fragment A). May you give me any reason and suggestion to solve it.
推荐答案
当您从应用设置撤消权限时-活动将重新启动,所有组件也将重新启动.但是在onCreate(...)中,savedInstanceState不等于null.
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){
if (savedInstanceState != null) {
}
使用上述hack应用恢复上一个fragmentC.
Using the above hack app resume last fragmentC.
这篇关于每次禁用设置权限时,活动都会重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!