如何 return 在 android fragmentTabHost 中进行分段

how to return to fragment in android fragmentTabHost

我画了这个问题:

有人知道解决办法吗?

ActivityA 开始 ActivityB 使用 startActivityForResult

int REQUEST_CODE = 99; // random number here
startActivityForResult(activityAIntent, REQUEST_CODE);

1) 在ActivityB调用:

  setResult(RESULT_OK);
  finish();

2) 在 ActivityA 中从 ActivityB 捕获 RESULT_OK:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == REQUEST_CODE) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
           // finish ActivityA and navigate back to FragmentA
           setResult(RESULT_OK);
           finish();
        }
    }
}

其他解决方案如果启动后不需要ActivityAActivityB,则在ActivityA中调用finish()从哪里开始 ActivityB。有了它,您只需在 ActivityB 中调用 finish(),用户将按预期导航回 FragmentA