Android 开发笔记___Intent的使用

【Android 开发笔记___Intent的使用】炒沙作縻终不饱,缕冰文章费工巧。这篇文章主要讲述Android 开发笔记___Intent的使用相关的知识,希望能为你提供帮助。

1 public class ActRequestActivity extends AppCompatActivity implements OnClickListener { 2 3private EditText et_request; 4private TextView tv_request; 5 6@Override 7protected void onCreate(Bundle savedInstanceState) { 8super.onCreate(savedInstanceState); 9setContentView(R.layout.activity_act_request); 10findViewById(R.id.btn_act_request).setOnClickListener(this); 11et_request = (EditText) findViewById(R.id.et_request); 12tv_request = (TextView) findViewById(R.id.tv_request); 13} 14 15@Override 16public void onClick(View v) { 17if (v.getId() == R.id.btn_act_request) { 18Intent intent = new Intent(); 19intent.setClass(this, ActResponseActivity.class); 20intent.putExtra("request_time", DateUtil.getNowTime()); 21intent.putExtra("request_content", et_request.getText().toString()); 22startActivityForResult(intent, 0); 23} 24} 25 26@Override 27protected void onActivityResult(int requestCode, int resultCode, Intent data) { 28if (data != null) { 29String response_time = data.getStringExtra("response_time"); 30String response_content = data.getStringExtra("response_content"); 31String desc = String.format("收到返回消息:\n应答时间为%s\n应答内容为%s", 32response_time, response_content); 33tv_request.setText(desc); 34} 35} 36 37 }

 
1 public class ActResponseActivity extends AppCompatActivity implements OnClickListener { 2 3private EditText et_response; 4private TextView tv_response; 5 6@Override 7protected void onCreate(Bundle savedInstanceState) { 8super.onCreate(savedInstanceState); 9setContentView(R.layout.activity_act_response); 10findViewById(R.id.btn_act_response).setOnClickListener(this); 11et_response = (EditText) findViewById(R.id.et_response); 12tv_response = (TextView) findViewById(R.id.tv_response); 13 14Bundle bundle = getIntent().getExtras(); 15String request_time = bundle.getString("request_time"); 16String request_content = bundle.getString("request_content"); 17String desc = String.format("收到请求消息:\n请求时间为%s\n请求内容为%s", 18request_time, request_content); 19tv_response.setText(desc); 20} 21 22@Override 23public void onClick(View v) { 24if (v.getId() == R.id.btn_act_response) { 25Intent intent = new Intent(); 26Bundle bundle = new Bundle(); 27bundle.putString("response_time", DateUtil.getNowTime()); 28bundle.putString("response_content", et_response.getText().toString()); 29intent.putExtras(bundle); 30setResult(Activity.RESULT_OK, intent); 31finish(); 32} 33} 34 35 }

 

    推荐阅读