Issue To Pass Arraylist From An Intent To Another
Before asking here, i first search how to pass an arraylist from an intent to another. Thanks to one of the post made on SO, I thought i found a way to do so. The thing is, when i
Solution 1:
intent.putExtra("arrayList",arrayList); this wrong in your code. Serializable the arraylist before pass like below
Try this code
ArrayList<Object> object = new ArrayList<Object>();
Intent intent = new Intent(Current.class, next.class);
Bundle args = new Bundle();
args.putSerializable("ARRAYLIST",(Serializable)object);
intent.putExtra("BUNDLE",args);
startActivity(intent);
In the next.class
Intent intent = getIntent();
Bundle args = intent.getBundleExtra("BUNDLE");
ArrayList<Object> object = (ArrayList<Object>) args.getSerializable("ARRAYLIST");
Solution 2:
Suppose strinclude is a simple arraylist of integers.
ArrayList<Integer> strinclude=new ArrayList<Integer>();
Activity 1:
//Here I am sending the arraylist to Activity2
Intent i=newIntent(MainActivity.this,ResultActivity.class);
i.putExtra("include",strinclude);
startActivity(i);
Activity 2:
//Here I am recieving the arraylist from Activity1
ArrayList<Integer> strinclude=new ArrayList<Integer>();
strinclude=(ArrayList<Integer>) getIntent().getSerializableExtra("include");
Thats it.
Post a Comment for "Issue To Pass Arraylist From An Intent To Another"