Reputation: 846
I have an intent which is searching data from a webservice. I'm trying to pass these datas from this intent to another screen (intent)
searching intent
public void setXXX(ArrayList<XXX> xxxData) {
this.xxxs= xxxData;
if(xxxData.size() > 0)
{
Intent intent = new Intent(this, otherActivity.class);
startActivity(intent);
}else{
alert (getResources().getString(R.string.no_result));
}
}
receiver intent
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.xxxs = (...);
setContentView(R.layout.activity_xxxlist);
this.xxxList = (ListView) findViewById(R.id.listview);
this.listView.setAdapter(new xxxDataAdapter(this,this.layoutInflator, this.xxxs));
}
How can i use my arrayList<> from the second intent ?
Upvotes: 0
Views: 111
Reputation: 9778
To be able to send Objects through Intents
, you have to implement Parcelable
interface for that object. It uses a CREATOR
to write Strings and primitive types of that object.
Here is the developer page for it.
Once you have done that, you can send that object in an ArrayList like this:
intent.putParcelableArrayListExtra(ArrayList<Parcelable> ... );
See this method: putParcelableArrayListExtra
And in the receiving activity, you can call:
getIntent().getParcelableArrayListExtra( String key );
Upvotes: 2