Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure delivering result ResultInfo

Tags:

There are many people who have encountered the same error on stackoverflow, but I haven't been able to find any relevant resolution in those posts. My MainActivity is starting a new activity (SecondActivity) with startActivityForResult(); SecondActivity then returns some data with onBackPressed(); and putExtra();

Extract from MainActivity.java:

public void addNewNote(View v){

    Intent intent = new Intent(this, SecondActivity.class);
    intent.putExtra("Source", "NEW");
    startActivityForResult(intent, 1); //1 is the result code

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    Log.v("TAG", data.getStringExtra("Note"));
      if (requestCode == 1) {

         if(resultCode == RESULT_OK){        
             listItems.add(data.getStringExtra("Note"));
             Log.v("TAG", data.getStringExtra("Note"));
             adapter.notifyDataSetChanged();
             listView.invalidateViews();
         }
         if (resultCode == RESULT_CANCELED) {   

         }
      }

}

Extract from SecondActivity.java:

@Override
public void onBackPressed() {

    super.onBackPressed();
    if (mainTextField.getText() != null){
        Intent returnIntent = new Intent();
        returnIntent.putExtra("Note",mainTextField.getText());
        setResult(RESULT_OK, returnIntent);     
        finish();
    } else {
        Intent returnIntent = new Intent();
        setResult(RESULT_CANCELED, returnIntent);        
        finish();
    }

}

Logcat:

Logcat

like image 539
timeshift117 Avatar asked Dec 26 '13 09:12

timeshift117


2 Answers

Try this-

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
      if (requestCode == 1 && data != null) 
      {
         Log.v("TAG", data.getStringExtra("Note"));
         if(resultCode == RESULT_OK)
         {        
             listItems.add(data.getStringExtra("Note"));
             Log.v("TAG", data.getStringExtra("Note"));
             adapter.notifyDataSetChanged();
             listView.invalidateViews();
         }
         if (resultCode == RESULT_CANCELED) 
         {   

         }
      }
}
like image 50
amit singh Avatar answered Sep 22 '22 18:09

amit singh


The problem with me was that I used getIntent(), thus getting the intent of the current activity I was on.

When I switched to data.getStringExtra() it worked. Amateur mistake...

like image 42
gigo Avatar answered Sep 20 '22 18:09

gigo