3

There are many question here from people having the exact same problem as I, and I've looked though a million, tried different things for 2-3 hours now, and I still can't get it working.

Child Activity:

Intent resultIntent = new Intent(myColorPicker.this, WidgetConfig.class);
resultIntent.putExtra("key", appwidget_notecolor);
setResult(RESULT_OK, resultIntent);
finish();

Parent Activity:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  // Toast does not show
  Toast.makeText(getApplicationContext(), "onActivityResult fired", Toast.LENGTH_SHORT).show();

  if (resultCode == RESULT_OK ) {
        // Toast does not show
        Toast.makeText(getApplicationContext(), "Result Recieved", Toast.LENGTH_SHORT).show();
    }
}

I launch child activity from parent activity like this:

Intent myColorPickerIntent = new Intent(WidgetConfig.this, myColorPicker.class);
myColorPickerIntent.putExtra("appwidget_notecolor", appwidget_notecolor);
WidgetConfig.this.startActivity(myColorPickerIntent);
Gene Bo
  • 10,022
  • 8
  • 81
  • 128
Jakob
  • 9,259
  • 14
  • 55
  • 76
  • 4
    Did you use `startActivityForResult()` or `startActivity()` for launching the child activity? – Eng.Fouad Apr 09 '13 at 22:53
  • @Eng.Fouad that was the problem, replacing startActivity() with startActivityForResult(), did fix it. Thank you – Jakob Apr 09 '13 at 23:07
  • Good details for using `startActivityForResult()`: http://stackoverflow.com/a/10407371/2162226 – Gene Bo Nov 30 '16 at 05:26

3 Answers3

12

Of course you won't get the result, you're calling startActivity() instead of startActivityForResult().

JoxTraex
  • 13,253
  • 6
  • 31
  • 45
5

You don't seem to be calling startActivityForResult() after creating the Intent.

Yojimbo
  • 21,502
  • 5
  • 41
  • 47
3

Are you pass the intent to startActivityForResult() method?

eltabo
  • 3,571
  • 1
  • 20
  • 33