Pass an array of custom objects + Android -


I am very new to Android development, there is a small problem facing here. I have a class animal. I need to pass an array of animal classes between two activities. I have searched for forums and have found that it can be done with identifiable, but I could not fully understand it. I tried to use serialjob but found exceptions. Please guide me how can this be done?

:

  ArrayList & LT; Animals & gt; Animal = new arreelist & gt; Animals & gt; (); // Fill your list with your animals here intent.putExtra ("animals", animals);   

Recover:

  Arreelist & gt; Animals & gt; Animal = (arrelisted & lt; animal & gt;) getIntent () .getSerializableExtra ("animal");   

Your class animal should implement the serialjob .

Edit: Please note that this approach is easy-to-implement, but it is time to periodically serialize and deorize the object, and if the array is large in size If there is a noticeable delay in change in activities (e.g., 100+ objects, or 10+ complexes, heavy objects). So please temporarily consider this approach and do not use it in the production code.

For greater efficiency, you can use parceltables as recommended by David Cantt. Here's an easy-to-use code generator for developers to avoid writing boilerplate code.

A good option can be done in local SBIT DB to get and retrieve from local DB in each decode. > Activity is required so you are only passing content url through intent.

Comments