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 create an Internet and then set the result as the intent, as in the following code.
private void getSearchData()
{
ArrayList<Spanned> passwords = null;
String searchTerm = txtSearch.getText().toString();
GetSearchResults search = new GetSearchResults(this, searchTerm);
if (rdoApp.isChecked())
{
passwords = search.getData(SearchType.App);
}
else if (rdoName.isChecked())
{
passwords = search.getData(SearchType.Name);
}
else if (rdoUsername.isChecked())
{
passwords = search.getData(SearchType.Username);
}
Intent intent = new Intent();
intent.putExtra("searchResults", passwords);
setResult(1, intent);
finish();
}
In the first activity in the function OnActivityResult
I then want to get the ArrayList so that I can process the data. I have the following code so far.
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
common.showToastMessage("Result received", Toast.LENGTH_LONG);
Bundle bundle = data.getExtras();
}
I have no idea where to go from here.
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();
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putSerializable("passwords", passwords);
intent.putExtras(bundle);
setResult(1, intent);
finish();
In the activity for inside the OnActivityResult function I have the following
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
common.showToastMessage("Result received", Toast.LENGTH_LONG);
Bundle bundle = data.getExtras();
ArrayList<Spanned> passwords = (ArrayList<Spanned>) bundle.getSerializable("passwords");
}