链接调用onActivityForResult不会返回对原始Activity的响应

时间:2019-05-22 14:10:36

标签: android android-intent android-activity

我有3个活动:

  1. LoadingInfoActivity(A)
  2. LoadingScanActivity(B)
  3. ReasonForSkipActivity(C)

这是所需的工作流程:

  1. A开始以B为结果
  2. B为结果开始C
  3. C完成并将结果返回给B
  4. B onActivityResult()方法从C获取返回的值
  5. B调用finish()返回A

但是,当应用程序到达我称为finish()的'B'的onActivityResult()方法时,我不会被引导回'A'。即使正在调用finish()方法,该应用仍保留在活动B上。

LoadingInfoActivity startActivityForResult()

 Intent scanLoad = new Intent(LoadingInfoActivity.this, 
 LoadingScanActivity.class);         
 startActivityForResult(scanLoad, SCAN_LOCATION);

LoadingScanActivity startActivityForResult()

 Intent reason = new Intent(LoadingScanActivity.this, 
 ReasonForSkip.class);
 startActivityForResult(reason, GET_SKIP_REASON);

ReasonForSkip代码可返回上一个活动

 Intent data = new Intent();
 data.putExtra(REASON, reason);
 setResult(RESULT_OK, data);
 finish();

LoadingScanActivity onActivityResult方法(此代码可以运行,但不会将我重定向到LoadingInfo onActivityResult方法

if (requestCode == GET_SKIP_REASON){
   String reason = data.getStringExtra("Reason");
   Intent loadingInfo = new Intent();
   data.putExtra("CageSkip", "Y");
   data.putExtra("Reason", reason);
   setResult(RESULT_OK, loadingInfo);
   finish();
}

LoadingInfoActivity onActivityResult方法(我们从未达到这一点)

if (requestCode == SCAN_LOCATION){
    if (resultCode == Activity.RESULT_OK) {
        String reason = data.getStringExtra("Reason");
        String skipped = data.getStringExtra("CageSkip");
        // Process results
    }
}

如果有一些文档或我想念的东西,我很高兴能为正确的方向指明为什么它不起作用。

0 个答案:

没有答案