Roger
Roger

Reputation: 6527

onActivityResult throws Failure delivering result ResultInfo

That's from the main code:

public void ChangeFlag(View view)
{
        Intent dialogIntent = new Intent(getBaseContext(), dialogPickFlag.class);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityForResult(dialogIntent, 1);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    Toast.makeText(this, data.getStringExtra("str") , 1500 ).show();

}

and this is from the activity, that's being called:

public void endResult(String s)
{
Intent intent = new Intent();
intent.putExtra("str", s);
setResult(RESULT_OK,intent);
    finish();
}

yet strangely it crashes with

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {Constructor.rob.com/Constructor.rob.com.constr}: java.lang.NullPointerException

Obviously only the request code has passes, but why not the response and data?

Any ideas? Thanks!

EDIT: Changed to toast to "Toast.makeText(this, "aaa" , 1500 ).show();" and noticed that it fires prematurely, then the new activity is created, not when it finishes!

Upvotes: 1

Views: 7732

Answers (2)

schspa
schspa

Reputation: 79

Actually, I solved it by assert the data as fellowing:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data == null)
  return;
else{
//...
   }
super.onActivityResult(requestCode, resultCode, data);
}

Upvotes: 0

Roger
Roger

Reputation: 6527

Solved it by using the setFlags method:

dialogIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Upvotes: 2

Related Questions