Start with callback

  MainActivity class

public void onClick(View v) {// v is the attempt object of the event user operation, which is the button
if(v == btn_main_start1){
//Toast.makeText(this,"normal start",Toast.LENGTH_SHORT).show( );
//Create an Intent object (display)
Intent intent = new Intent(this,SecondActivity.class);
String message = et_main_msg.getText().toString().trim();
intent.putExtra("MSG", message) ;
//Start Activity
startActivity(intent);
}else if(v == btn_main_start2){
// Toast.makeText(this,"start with callback",Toast.LENGTH_SHORT).show(); //Create an Intent object (display ) Intent intent = new Intent(this,SecondActivity.class); //carry extra data through Intent String message = et_main_msg.getText().toString().trim();





intent.putExtra("MSG", message);
//Start Activity with callback
int requestCode = 2;
startActivityForResult(intent, requestCode); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Judge COde if(requestCode==2 && resultCode==3){ //Get data from date String result = data.getStringExtra("RESULT"); //Display the result et_main_msg.setText(result); } }          }













class secondActivity

et_secd_msg = (EditText) findViewById(R.id.et_secd_msg);
//Get INTET object
Intent intent = getIntent();
//Read extra data
String message = intent.getStringExtra("MSG");
//Display to EdiText
et_secd_msg.setText(message);
}
public void back1(View v){
//Close the current interface
finish();
} //The second button public void back2 (View v){ //Save a result int resultCOde = 3; //Prepare an intent object with extra data Intent date = new Intent(); String result= et_secd_msg.getText().toString().trim(); date.putExtra("RESULT", result); //set result setResult(resultCOde,date); //Close the current interface finish(); }















}

operation result


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325812423&siteId=291194637