简体   繁体   中英

onActivityResult not called

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);

当然你不会得到结果,你正在调用startActivity()而不是startActivityForResult()。

在创建Intent之后,您似乎没有调用startActivityForResult()。

你是否将意图传递给startActivityForResult()方法?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM