Updated 6 October 2017
In the blog, we have shown you how to pass the List of CustomObjects to the Activity and fragment.
In this technique, we have used the Serialization for the list passing.
Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
Step 1: Implements your model With Serializable interface,
Step 2:
| 1 | (new HomeTabProductsFragment()).newInstance((Serializable) mainData.getData().getFeaturedProduct(), ""); | 
| 1 2 3 4 5 6 7 8 |  public static HomeTabProductsFragment newInstance(Serializable param1, String param2) {         HomeTabProductsFragment fragment = new HomeTabProductsFragment();         Bundle args = new Bundle();         args.putSerializable(ARG_PARAM1, param1);         args.putString(ARG_PARAM2, param2);         fragment.setArguments(args);         return fragment;     } | 
| 1 2 3 |  Intent intent = new Intent(getActivity(), Activity.class);                 intent.putExtra("list", (Serializable) mainData.getData().getFeaturedProduct());                 getActivity().startActivity(intent); | 
| 1 | ((List<HomeProductsModel>) getIntent().getExtras().getSerializable("list")) | 
If you have any doubt on this blog, please ask in comments. And stay updated and stay super.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.