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!
Solved it by using the setFlags method:
dialogIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
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);
}
精彩评论