soulqw/SoulPermission

对Fragment请求权限有个疑问

forJrking opened this issue · 1 comments

简单看了下代码,思路还是很棒的!!!
空的Fragment请求完毕权限是不是应该解绑掉释放下占用资源会好点呢?
或者我没看到这个部分逻辑。

public static void detachFragment(Object obj) { if (obj instanceof android.support.v4.app.Fragment) { android.support.v4.app.Fragment fragmentSupport = (android.support.v4.app.Fragment) obj; if (!fragmentSupport.isAdded()) return; android.support.v4.app.FragmentTransaction transaction = fragmentSupport.getFragmentManager().beginTransaction(); transaction.detach(fragmentSupport); transaction.remove(fragmentSupport); transaction.commitAllowingStateLoss(); } else if (obj instanceof android.app.Fragment) { android.app.Fragment fragmentApp = (android.app.Fragment) obj; if (!fragmentApp.isAdded()) return; android.app.FragmentTransaction fragmentTransaction = fragmentApp.getFragmentManager().beginTransaction(); fragmentTransaction.detach(fragmentApp); fragmentTransaction.remove(fragmentApp); fragmentTransaction.commitAllowingStateLoss(); } }

感谢提出issue
至于为什么没有使用移除的逻辑考虑下来有两点:
1.Fragment 没有界面,其实不会占用太多资源
2.真运行时权限一般请求时调用,如果一个页面有多个操作,打电话,读取联系人,可以互用权限fragment,比如我sample里面的 ApiGuideActivity,每个按钮都对应有权限,这样互用效率更高