一个transaction异常的处理

11-16 14:13:47.715: W/dalvikvm(16771): threadid=1: thread exiting with uncaught exception (group=0x4373e160)
11-16 14:13:47.715: E/AndroidRuntime(16771): FATAL EXCEPTION: main
11-16 14:13:47.715: E/AndroidRuntime(16771): Process: com.zyt.veblife, PID: 16771
11-16 14:13:47.715: E/AndroidRuntime(16771): java.lang.IllegalStateException: Activity has been destroyed
11-16 14:13:47.715: E/AndroidRuntime(16771):     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1383)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:578)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at com.zyt.veblife.ShopDetailActivity.initData(ShopDetailActivity.java:557)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at com.zyt.veblife.ShopDetailActivity.access$0(ShopDetailActivity.java:471)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at com.zyt.veblife.ShopDetailActivity$1.handleMessage(ShopDetailActivity.java:103)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at android.os.Handler.dispatchMessage(Handler.java:102)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at android.os.Looper.loop(Looper.java:149)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at android.app.ActivityThread.main(ActivityThread.java:5045)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at java.lang.reflect.Method.invokeNative(Native Method)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at java.lang.reflect.Method.invoke(Method.java:515)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
11-16 14:13:47.715: E/AndroidRuntime(16771):     at dalvik.system.NativeStart.main(Native Method)

如上异常,活动已经被销毁。

主要是Transaction的commit方法时,出现的错误,

// 开启事物
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        // if (headviewPager == null) {
        // headviewPager = new GoodsDetailHeadViewPagerFragment();
        // headviewPager.setGoodsDetail(goodsDetail);
        // transaction.add(R.id.fragment_head_detail_page, headviewPager);
        // }

        if (goodsAttr == null) {
            goodsAttr = new GoodsDetailGoodsAttrFragment();
            goodsAttr.setGoods(goodsDetail.getGoods());
            transaction.add(R.id.fragment_goods_attr_area, goodsAttr);
        }

        // 事物提交
        if (transaction != null) {
//            transaction.commitAllowingStateLoss();
            transaction.commit();
        }

就这么写,之后测了几次没有出现这个错误了。但是我觉得还是没有解决

posted @ 2015-11-16 16:06  likeshu  阅读(1096)  评论(0编辑  收藏  举报