Skip to content Skip to sidebar Skip to footer

Getting Arraylist From Onactivityresult Function Saved Inside Intent

I am currently working on an android project and I have an activity that is started using the startActivityForResult() function. Within this activity I have an ArrayList and I cre

Solution 1:

I've managed to find a way, it is thank to @Jan Gerlinger answer pointed me in the correct direction but I've found how to do it.

In the activity where I am setting the result I have the following code

ArrayList<Spanned> passwords = search.getResult();
Intentintent=newIntent();
Bundlebundle=newBundle();
bundle.putSerializable("passwords", passwords);
intent.putExtras(bundle);
setResult(1, intent);
finish();

In the activity for inside the OnActivityResult function I have the following

protectedvoidonActivityResult(int requestCode, int resultCode, Intent data)
{
common.showToastMessage("Result received", Toast.LENGTH_LONG);
Bundlebundle= data.getExtras();
ArrayList<Spanned> passwords = (ArrayList<Spanned>) bundle.getSerializable("passwords");
}

Solution 2:

intent.putExtra("searchResults", passwords);

here uses the putExtra(String name, Serializable value) method. So you can use getSerializableExtra(String name) to get it back:

ArrayList<Spanned> passwords = (ArrayList<Spanned>) data.getSerializableExtra("searchResults");

Depending on the type of your Spanned objects and if they do implement Serializable, this may however throw Exceptions as Spanned does not implement Serializable directly.

Post a Comment for "Getting Arraylist From Onactivityresult Function Saved Inside Intent"