AndroidStudio: java. How can i return an arraylist to main activity?

Tags: , , ,



I tried this way:
The application stops working on setResult only when the arraylist is not empty.
SECONDARY ACTIVITY

Intent d = new Intent();
d.putExtra("cat",(Serializable)  category.categories);
setResult(RESULT_OK, d);
finish();

CATEGORIES INITIALIZATION:

public ArrayList<buy_categories2> categorie= new ArrayList<buy_categories2>();

MAIN ACTIVITY in the method onActivityResult:

ArrayList<buy_categories2> b2 = new ArrayList<buy_categories2>();
b2 = (ArrayList<buy_categories2>) data.getExtras().getSerializable("cat");

Answer

buy_categories2 must be Serializable



Source: stackoverflow