更改权限设置后从最近的任务重新打开时,将调用onCreate() [英] onCreate() gets called when reopen from recent task after permission settings is changed

查看:83
本文介绍了更改权限设置后从最近的任务重新打开时,将调用onCreate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题标题听起来似乎很复杂,但这是我的情况.

The question title may sounds complicated but here is my situation.

我在一个活动中有一个地图片段.简单的. 启用存储"权限以允许显示地图,效果很好. 通过按主页"按钮使应用程序后台运行,然后关闭存储"权限并从最近的任务中打开应用程序,应用程序崩溃.

I have a map fragment within an activity. Simple. turn on Storage permission to allow display of Map, works fine. Backgrounds the app by pressing Home button, then turn off the Storage permission and open the app from recent task, app crashes.

问题在于,不是调用宿主Activity的onResume(),而是在宿主Activity和Map片段的onCreateView()上调用了onCreate().因此,它引发了异常.

The problem is instead of calling onResume() of the host Activity, onCreate() is called on the host Activity as well as onCreateView() of the Map fragment. Thus it is throwing Exceptions.

当更改权限并因此重新创建Activity时,似乎终止了应用程序进程.

It seems like the app process is killed when permission is changed and thus Activity is recreated.

    09-24 14:42:55.071: E/AndroidRuntime(12918):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
09-24 14:42:55.071: E/AndroidRuntime(12918): Caused by: 
java.lang.NullPointerException: Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim' on a null object reference
09-24 14:42:55.071: E/AndroidRuntime(12918):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:718)
09-24 14:42:55.071: E/AndroidRuntime(12918):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
09-24 14:42:55.071: E/AndroidRuntime(12918):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)

来自Activity的super.onStart()

From super.onStart() from the Activity

推荐答案

可行的解决方案只是在Activity的onCreate()中调用getSupportFragmentManager().popBackStackImmediate();,以防止尝试重新创建地图片段.

The workable solution now is just to call getSupportFragmentManager().popBackStackImmediate(); in onCreate() of the Activity to prevent from trying to recreate the map fragment.

popBackStack()在这种情况下不起作用,因为它是异步的.

popBackStack() won't work in this case as it is asynchronous.

这篇关于更改权限设置后从最近的任务重新打开时,将调用onCreate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆