Reputation: 25
Background:
My Goal:
Problem:
java.lang.RunTimeException: Failure delivering results ResultInfo{who=null, request=1,
result=0, data=Intent { (has extras) }} to activity.
I think I made a huge mistake but I couldn't solve it.
switch case from onOptionsItemSelected and onActivityResult are in the MainActivity:
PICKED has the value 1;
switch (item.getItemId()) {
case R.id.icon:
Intent myIntent = new Intent(MainActivity.this, HeroListActivity.class);
MainActivity.this.startActivityForResult(myIntent, PICKED);
return true;
default:
return super.onOptionsItemSelected(item);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
Intent intent = getIntent();
HashMap<String, String> aList = (HashMap<String, String>)intent.getSerializableExtra("map");
Log.d("HashMap", aList.get("Name"));
}
}
onItemClick in the SubActivity with the ListView:
onItemClick is working and I get the correct data from the HashMap when I use Log.d.
HashMap<String, String> o = (HashMap<String, String>) adapter.getItemAtPosition(position);
Log.d("onItemClick", ""+o);
Intent intent = new Intent();
intent.putExtra("map", o);
setResult(RESULTS_OK, intent);
finish();
I hope someone can help me and thanks in advance.
Upvotes: 1
Views: 376
Reputation: 8680
You should replace this line in your onActivityResult()
method
Intent intent = getIntent();
with this:
Intent intent = data;
data
is the name of a parameter you are passing in - that's where your extras reside. getIntent()
call returns a null
intent in this instance.
Upvotes: 1