kayzer soze kayzer soze - 7 months ago 21
Android Question

How can I add to array my custom class and pass Intent

I simply want to add array to my custom class like "Dog" class to array and put it to Intent after that I want to get that extras using getIntent().getExtra() ... But I struggle with it.

ArrayList<String> list = new ArrayList<String>();

JSONArray jobList = (JSONArray) response.get("sonuclar");
JSONObject jsonObject;

for( int i = 0; i < jobList.length(); i++) {
jsonObject = jobList.getJSONObject(i);

String jobTitle = jsonObject.getString("baslik");
String firmName = jsonObject.getString("firma_adi");
String jobDate = jsonObject.getString("tarih");
String jobSummary = "" ;
String jobImageURL = jsonObject.getString("logo");

jobItem = new JobItem(jobTitle,firmName, jobDate, jobSummary, jobImageURL);
// this code will start new intent

/* intent view */
private void goJobListView(Object[] results) {

Intent jobIntent = new Intent(this, JobListActivity.class);
jobIntent.putExtra("job_data", results);

Here is my trouble how can I get that custom class JobItem from another activity.

Thank you.


How can I add to array my custom class and pass Intent

Easy approach is mark custom class Serializable then use intent.putExtra(key,custom_class_object_arraylist); to send data to next Activity.

In next Activity use intent.getSerializableExtra method to get custom object Array from Intent:

Intent intent = getIntent();
ArrayList<JobItem> job_data = 

Second and good approach is mark JobItem class as Parcelable then use Intent.putParcelableArrayListExtra and Intent.getParcelableArrayListExtra to send and get list of custom objects from Intent.

For more help you can see following example: Android: Passing ArrayList of Object Within an Intent