如何从 activity 到特定片段

How to intent from activity to specific fragment

我有一个带有底部导航栏菜单的主菜单, 在导航栏菜单的最后一个选项卡中,我创建了一个按钮以用于其他 activity、

这个按钮来自一个带有 BottomNavbar 的 Activity 打开另一个 activity

  @OnClick(R.id.scanQR)
    public void onScan() {
        startActivity(new Intent(getContext(),Action_camera.class));
    }

在其他 activity 我只是用它来获取 QRcode 并将 QRcode.result (字符串)发送回我在这种情况下使用的最后一个片段第 3 号片段

如果我使用 intent to parent activity 来自 fragment no 3 它只会显示 fragment no one

@OnClick(R.id.cariqr)
    public void onClickqr() {
        Bundle args= new Bundle();
        args.putString("kodebmnscan",textView.getText().toString().trim());
        frag_asset_admin bundle = new frag_asset_admin();
        bundle.setArguments(args);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.container, bundle).commit();
    }

如何从 activity

返回导航栏菜单的最后一个选项卡

我没有正确理解您的问题,但据我所知,我可以帮助您了解如何浏览片段和活动:

要从 activity 移动到 activity 或片段到 activity,您可以使用简单的意图:

Intent intent=new Intent(CurrentActivity.this,NextActivity.class);
startActivity(intent);

要在 ViePager 中加载片段,您只需使用 FragmentManager,例如:

getSupportFragmentManager().beginTransaction().replace(R.id.ViewPagerID, context).commit();

因此,要开始activity获取结果,您需要将获取结果的二维码返回首页activity。您将执行如下步骤:

开始 activity 结果:

startActivityForResult(new Intent(context,QRCODE.class),REQUEST_CODE);

发回数据

Intent returnIntent = new Intent();
returnIntent.putExtra("result",result);
setResult(Activity.RESULT_OK,returnIntent);
finish();

如果你不想return数据:

Intent returnIntent = new Intent();
setResult(Activity.RESULT_CANCELED, returnIntent);
finish();

在 'homeactivity' 接收数据:

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

if (requestCode == LAUNCH_SECOND_ACTIVITY) {
    if(resultCode == Activity.RESULT_OK){
        String result=data.getStringExtra("result");
    }
    if (resultCode == Activity.RESULT_CANCELED) {
        //Write your code if there's no result
    }
  } 
}

如果我没有回答你的问题,请详细说明你的问题,我会尽力回答。