Bundle does not fully received
I am facing a problem with sending data through the bundle.
Intent toAudio = new Intent(TourDescription.this, Audio.class);
toAudio.putParcelableArrayListExtra("poi", arraypoi);
startActivity(toAudio);
here am sending arraypoi
which is an ArrayList. This ArrayList contains a set of values.
And in the receiving class, I have like this
listOfPOI = getIntent().getParcelableArrayListExtra("poi");
Collections.sort(listOfPOI);
where listOfPOI
is also an array list.
The problem am facing is, I am not able to receive values for 3 particular variables in listOfPOI
(coming as null
), rest all values are coming proper.
While sending the bundle, I mean in arraypoi
also I am able to send all the values correct开发者_C百科ly but the problem is while receiving it.
Note: My class is implemented as parcelable
only.
Any answer for this?
There are two workarounds in my point of view.
First:
You need to make YourOwnArrayList
as subclass of ArrayList<YourObject>
and implements
Parcelable
.
Tutorial Here
Second:
pass your Object using for()
loop. like this.
Intent toAudio = new Intent(TourDescription.this, Audio.class);
toAudio.putExtra("SIZE", arraypoi.size());
for(int i=0; i<arraypoi.size(); i++)
toAudio.putExtra("POI"+i, arraypoi.get(i));
startActivity(toAudio);
and while getting in other class
Bundle data = getIntent().getExtras();
int size=data.getInt("SIZE");
for(int i=0; i<size; i++)
listOfPOI.add((YOUR_OBJECT) data.getParcelable("POI"+i));
YOUR_OBJECT
is the class name of your Object
.
精彩评论