Main Activity:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
TextView v1 = (TextView) this.findViewById(R.id.textView1);
TextView v2 = (TextView) this.findViewById(R.id.textView2);
v1.setText( "FirstNum:");
v2.setText( "SecondNum");
final TextView vA = (TextView) this.findViewById(R.id.txtA);
final TextView vB = (TextView) this.findViewById(R.id.txtB);
Button b = (Button) this.findViewById(R.id.btnAdd);
b.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String strA = vA.getText().toString();
String strB = vB.getText().toString();
Intent intent = new Intent();
intent.putExtra( "A", strA);
intent.putExtra( "B", strB);
intent.setClass(MainActivity. this, Activity02.class);
startActivity(intent);
finish();
}
});
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity02);
Intent intent = this.getIntent();
String strA = intent.getStringExtra( "A");
String strB = intent.getStringExtra( "B");
int a = Integer.parseInt(strA);
int b = Integer.parseInt(strB);
int c = a + b;
Intent intent = new Intent(MainActivity.this, Activity01.class);
startActivityForResult(intent, 0);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
tv.setText(data.getStringExtra("return"));
}
}
Intent intent = new Intent();
intent.putExtra("return", "ABC");
setResult(RESULT_OK, intent);
finish();