OnActivityResult not called after startIntentSenderForResult

左心房为你撑大大i 提交于 2019-12-05 09:44:57

The key was to call the below method in the first activity.

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

Add this in your outer Activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.change_to_your_id);
  fragment.onActivityResult(requestCode, resultCode, data);
}

To properly solve this problem You might use already prepared solution accountPicker.
However - If You want to devise Your own solution - one idea is to start Your second activity (from first activity obviously) with:

Intent intent = this.getIntent();
intent.putExtra(... /* some code that will control second activity */
startActivityForResult(intent, request_code);

and then when activity did all it had to do You allow it to return:

Intent intent = this.getIntent();
intent.putExtra(... /* all needed results to return */ );
this.setResult(RESULT_OK, intent);
finish();

finally it is Your first activity that then gets result in its onActivityResult.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!