I have a Child Activity which is returning an ArrayList to Parent Activity
Child Activity
ArrayList<Users> selectedMembers = new ArrayList<Users>();
//And then
Intent returnIntent = new Intent();
returnIntent.putExtra("ArrayOfUsers",selectedMembers);
setResult(RESULT_OK,returnIntent);
finish();
Parent Activity
Now how to get this ArrayList<Users> on parent Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode == RESULT_OK) {
//how to get ArrayList<Users> here
}
}
I did something like this but i gives error
selectedMembers.addAll((data.getParcelableArrayListExtra("ArrayOfUsers"));
error:
The method addAll(Collection<? extends Users>) in the type ArrayList<Users> is not applicable for the arguments (ArrayList<Parcelable>)
You are using different methods for serialization and deserialization. When you call
returnIntent.putExtraactually this overloaded method inIntentclass is called. So your list of users is actually treated as singleSerializableobject. In this caseputExtraat child side should be used in conjunction withgetSerializableExtragetter at parent side.If you want to use
getParcelableArrayListExtraat parent side as getter method you should use it in conjunction withputParcelableArrayListExtraat child side and youUsersclass should beParcelable.