简体   繁体   中英

Getting null values when passing data from activity to fragment using Parceable

I am trying to pass arraylist from activity to fragments but i am getting a null value using the parceable.

In Main Activity:

Bundle bundle = new Bundle();
                    bundle.putParcelableArrayList("cbookings", customerbooking);
                    Todaybooking tb = new Todaybooking();
                    tb.setArguments(bundle);

Array list data declarations

ArrayList<Cbooking> customerbooking = new ArrayList<>();

In fragments:

ArrayList<Cbooking> customerbooking = new ArrayList<>();

    Bundle extras = getActivity().getIntent().getExtras();
    customerbooking = extras.getParcelableArrayList("cbookings");
    Log.wtf("test", customerbooking.toString());

You are using setArguments() to pass the data into the fragment. Therefore, you need to use getArguments() to retrieve the data, not getActivity().getIntent().getExtras() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM