How to send text from one Activity to another Activity?

后端 未结 2 1711
我寻月下人不归
我寻月下人不归 2020-12-15 14:50

calculated.java: (this has to command to show the calculated.xml layout)

public class Calculated extends Activity {


   public void onCreate(Bundle savedIns         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 15:18

    To send the data from one activity to another activity

    MainActivity.java is first activity from where you want to send data to another activity.

    Intent myIntent = new Intent(view.getContext(), Calculated.class);
    myIntent.putExtra("text", text);
    startActivity(myIntent);
    

    Calculated.java is second activity which receive the intent data whatever you pass from MainActivity.java

    String text = myIntent.getStringExtra("text");
    TextView textView = (TextView)findViewById(R.id.textView1);
    textView.setText(text);
    

提交回复
热议问题