How to send string from one activity to another?

后端 未结 8 2218
庸人自扰
庸人自扰 2020-11-22 14:36

I have a string in activity2

String message = String.format(
\"Current Location \\n Longitude: %1$s \\n Latitude: %2$s\", lat, lng); 

I wan

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 14:51

    Say there is EditText et1 in ur MainActivity and u wanna pass this to SecondActivity

    String s=et1.getText().toString();
    Bundle basket= new Bundle();
    basket.putString("abc", s);
    Intent a=new Intent(MainActivity.this,SecondActivity.class);
    a.putExtras(basket);
    startActivity(a);
    

    now in Second Activity, say u wanna put the string passed from EditText et1 to TextView txt1 of SecondActivity

    Bundle gt=getIntent().getExtras();
    str=gt.getString("abc");
    txt1.setText(str);
    

提交回复
热议问题