getResources Fragment not attached to Activity

错误堆栈详情:

getResources Fragment not attached to Activity

这种情况一般出现场景fragment执行耗时任务(一般是网络操作),在执行完毕之前用户操作fragment退出,导致fragment 与父Activity 失去关联(disAttach),当我们调用getResource时,操作之前默认调用了getActivity ,因此会报错

   解决方法:

            1.在使用getResource之前 加判断fragment是否和activity失去关联 isAdded(),如果使用getResource比较多的时候可以把判断加在网络返回结果处理的地方;

getResources Fragment not attached to Activity

            2.采用一activity多fragmeng的情况下可以在可以写一个BaseFragment,其他fragment继承

getResources Fragment not attached to Activity

   当使用getResource()时,可以这样写 mMainActivity.getResource()..