How to send string from one activity to another?

后端 未结 8 2270
庸人自扰
庸人自扰 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 15:13

     Intent intent = new Intent(activity1.this, activity2.class);
     intent.putExtra("message", message);
     startActivity(intent);
    

    In activity2, in onCreate(), you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it :

      Bundle bundle = getIntent().getExtras();
      String message = bundle.getString("message");
    

提交回复
热议问题