How to send string from one activity to another?

后端 未结 8 2132
庸人自扰
庸人自扰 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

    Intents are intense.

    Intents are useful for passing data around the android framework. You can communicate with your own Activities and even other processes. Check the developer guide and if you have specific questions (it's a lot to digest up front) come back.

    0 讨论(0)
  • 2020-11-22 15:15

    You can send data from one actvity to another with an Intent

    Intent sendStuff = new Intent(this, TargetActivity.class);
    sendStuff.putExtra(key, stringvalue);
    startActivity(sendStuff);
    

    You then can retrieve this information in the second activity by getting the intent and extracting the string extra. Do this in your onCreate() method.

    Intent startingIntent = getIntent();
    String whatYouSent = startingIntent.getStringExtra(key, value);
    

    Then all you have to do is call setText on your TextView and use that string.

    0 讨论(0)
提交回复
热议问题