Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
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,
public class MyProductModel implements Serializable { @SerializedName("productName") @Expose private String productName; @SerializedName("productSDesc") @Expose private String productSDesc; @SerializedName("price") @Expose private Price price; @SerializedName("imageUrl") @Expose private String imageUrl; public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getProductSDesc() { return productSDesc; } public void setProductSDesc(String productSDesc) { this.productSDesc = productSDesc; } public Price getPrice() { return price; } public void setPrice(Price price) { this.price = price; } public String getImageUrl() { return imageUrl; } public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } } 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 public class MyProductModel implements Serializable { @SerializedName("productName") @Expose private String productName; @SerializedName("productSDesc") @Expose private String productSDesc; @SerializedName("price") @Expose private Price price; @SerializedName("imageUrl") @Expose private String imageUrl; public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getProductSDesc() { return productSDesc; } public void setProductSDesc(String productSDesc) { this.productSDesc = productSDesc; } public Price getPrice() { return price; } public void setPrice(Price price) { this.price = price; } public String getImageUrl() { return imageUrl; } public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } }
Step 2:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = (List<HomeProductsModel>) getArguments().getSerializable(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } } 12345678 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = (List<HomeProductsModel>) getArguments().getSerializable(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } }
If you have any doubt on this blog, please ask in comments. And stay updated and stay super.
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
We've bought a Shopware Extension which is a hybrid App, which we can now offer in the Google Play Store and the IOS App Store. I'am still impressed how fast and how sharp the support team leads us through every process of the App-Store clarification. Very fast and useful response.
Markus Walter
Founder, Das Apartment Living
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.