Android 開発における順方向および逆方向の値の転送

Android 開発における順方向および逆方向の値の転送

最初の定義、頭に注目してください

 String fxstr="矢量地图";

    //1.反向传值
    ActivityResultLauncher<Intent> launcher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == RESULT_OK) {
                    //拿到返回的数据
                     fxstr = result.getData().getStringExtra("data");
                    Toast.makeText(MainActivity.this, fxstr, Toast.LENGTH_SHORT).show();
                }
            });

ジャンプ

  //反向传值2
     // bt_lay = (ImageView) findViewById(R.id.sa_lay);//2
      findViewById(R.id.sa_lay).setOnClickListener(view -> {
          //使用
          Intent intent2 = new Intent(this,MapLaysetActivity.class);
          intent2.putExtra("name",fxstr);
          launcher.launch(intent2);
      });

戻る


void  fxvalue(){

    //请求返回结果
    ActivityResultLauncher<Intent> launcher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == RESULT_OK) {
                    //拿到返回的数据
                    String str = result.getData().getStringExtra("data");
                    Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
                }
            });

2ページ目

//インテントオブジェクトを取得します
tent = getIntent(); 
name =tent.getStringExtra("name");

============

名前= radbtn.getText()+""; 

インテントの意図 = new Intent(); 
インテント.putExtra("データ", 名前); 
setResult(RESULT_OK, インテント); 
仕上げる();

おすすめ

転載: blog.csdn.net/wushijun5200/article/details/129890168