Parceable ArrayLists (Android) - android

Im trying to pass objects with intents between activities in an Android app. I know that objects must be made parceable or serializable (sorry for my spelling) before they can be passes through intents. However, in my case the objects are in an array list when they are passed through the intent.
Do I have to make the arraylist parceable before I pass it? Or do I simply have to make the objects in the list parceable when I pass it? Iv'e been having a lot of trouble passing theses array lists and would appreciate any help. Thanks.

Objects in ArrayList should be parcelable. Here is good example on how to do it.Android arraylist parcelable

Related

Sendind an Extra with my own kind of data

I need to pass an extra data to an activity, but I don't know how since my data is a variable from a specific class of mine. I have something like:
MyClass variable=new MyClass();
Intent intent= new Intent(this,SecondActivity.class);
intent.putExtra("variableName", variable);
I know the error in code is obvious, but I want to know how can I send data from a class of mine.
Please looking into Parcelable
How can I make my custom objects Parcelable?
http://developer.android.com/reference/android/os/Parcelable.html
You will have to serialize the data and then pass. Android doesn't support passing custom objects as extras. Look at this answer here. Passing custom objects between activities?

How to transfer an ArrayList of objects from one Activity to another

I have an ArrayList of objects in one activity and I need this arrayList in another activity.
Is there a solution to transger this ArrayList? I know i can use intents for ArrayList of Strings but what's about the ArrayList of objects?
Thank you.
Complex types passed by means of Parcelable or do the serialization to another kind of primitive object that you can put to Intent's extras. see this question:
Help with passing ArrayList and parcelable Activity
and this tutorial:
Passing a list of objects between Activities

Passing arraylist in intent from one activity to another

I have a class 'Product' and i need to pass the arraylist of 'Product' objects from one activity to another.
I read that i can do so by making my Product class as Parcelable and use : putParcelableArrayListExtra (String name, ArrayList value).
In my app, i need to pass arraylists of objects from one activity to another. In this case, i need to make all those classes as parcelable and implement the interface methods.
Is this the correct way to solve the problem? Is there any other way to send the list of objects in intents?
Thanks..
Yes, the correct way is to use Parcelable or do the serialization to another kind of primitive object that you can put to Intent's extras

What's the best practice to pass data between Activities? Should I favor Parceable over Serializable as Intent Extra?

I'm developing an app which basically navigates through a xml-feed. When I parse the feed or let's say the list, then each (list)item becomes a model. All the models are wrapped up in an array list.
Now, when the user clicks on a list item, the underlying model is going to be serialized and sent as IntentExtra to the next Activity (e.g. a deeper sub list).
If you wan't to send complex objects with putExtra() they should implement the Parcelable interface.

Android: Send arbitrary objects within Activities?

I have read some question here but I didn't find a solution. I have read about Parcelable, Intents, and sharing specific data within Activities from the android dev docs (both dev guide and reference).
Here's the scenario:
I have one ListActivity that fills in an object parsing an xml file, it shows a list of values, and when clicked I want to return the object that represents the item clicked to the activity that has called it, for then, call another activity with this object.
I read on how to implement Parcelable but seems not being the way. Implementing Parcelable receives a Parcel for the constructor and then reads the values from it (or at least that was what I understood). This makes no sense for me and I can't see how to implement basing on that issue. I build the object parsing the xml file, not having a Parcel.
I appreciate some clarifications on this, regards.
I believe you have three options here:
Pass some arbitrary 'id' of the object to the new activity in the intent extras, which obtains the object in the same way as the first activity. This I would recommend as it is in harmony with the way Android is designed to work.
Serialize the object using Java Serializable, then put it into the intent as an extra.
Have the object be a JSONObject and send it as a string in the intent extras.
That depends on whether the activities belong to the same process or different ones...if it is the same process then the answer is Within an application what is the best way to pass custom objects between activities? but if they belong to different processes then you are better of implementing parcelable.

Categories

Resources