Got exception: fragment already active

前端 未结 8 1665
攒了一身酷
攒了一身酷 2021-01-30 12:49

I have a fragment;

MyFragment myFrag = new MyFragment();

I put bundle data to this fragment:

         


        
相关标签:
8条回答
  • 2021-01-30 13:27

    Just call public method from fragment

    if(userFragment==null){
                        userFragment = new UserFragment();
                        Bundle bundle = new Bundle();
                        bundle.putString(Constants.EXTRA_CUSTOMER, result);
                        userFragment.setArguments(bundle);
                    }else{
                        try {
                            Customer customer = new Customer();
                            customer.parseCustomer(new JSONObject(result));
                            userFragment.updateVeiw(customer);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
    
    0 讨论(0)
  • 2021-01-30 13:29

    remove() change fragment status to de-actiive. In your case, you just didn't call commit() after remove(..).

    fragmentTransaction.remove(activeFragment);
    

    You would do commit() after remove(), too.

    fragmentTransaction.remove(activeFragment).commit();
    
    0 讨论(0)
提交回复
热议问题