Thursday, April 25, 2013

How to pass data between activities in android app

Below is a tutorial how to pass data between Android activities.

Within your class declare a TextView, EditText and Button.

TextView tv;
EditText et1;
Button b1;

public void onCreate() {

tv = (TextView)findViewById(R.id.textView1);
et1 = (EditText)findViewById(R.id.edit1);
b1 = (Button)findViewById(R.id.but1);

public void onClick() {

String test = et1.getText();
Intent i = new Intent(this,newClass.Class);
i.putExtra("myKey",test);
startActivity(i);


}

Check out my golf game for iPhone by clicking here

1 comment: