Transferencia de valor hacia adelante y hacia atrás en el desarrollo de Android

Transferencia de valor hacia adelante y hacia atrás en el desarrollo de Android

Primera definición, presta atención a la cabeza.

 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();
                }
            });

saltar

  //反向传值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);
      });

devolver


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();
                }
            });

Segunda pagina

//Obtener el objeto de intención 
intent = getIntent(); 
name = intent.getStringExtra("name");

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

nombre= radbtn.getText()+""; 

Intención intención = nueva Intención(); 
intent.putExtra("datos", nombre); 
setResult(RESULT_OK, intención); 
finalizar();

Supongo que te gusta

Origin blog.csdn.net/wushijun5200/article/details/129890168
Recomendado
Clasificación