Android 开发笔记___Intent的使用
Posted alm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 开发笔记___Intent的使用相关的知识,希望对你有一定的参考价值。
1 public class ActRequestActivity extends AppCompatActivity implements OnClickListener { 2 3 private EditText et_request; 4 private TextView tv_request; 5 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_act_request); 10 findViewById(R.id.btn_act_request).setOnClickListener(this); 11 et_request = (EditText) findViewById(R.id.et_request); 12 tv_request = (TextView) findViewById(R.id.tv_request); 13 } 14 15 @Override 16 public void onClick(View v) { 17 if (v.getId() == R.id.btn_act_request) { 18 Intent intent = new Intent(); 19 intent.setClass(this, ActResponseActivity.class); 20 intent.putExtra("request_time", DateUtil.getNowTime()); 21 intent.putExtra("request_content", et_request.getText().toString()); 22 startActivityForResult(intent, 0); 23 } 24 } 25 26 @Override 27 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 28 if (data != null) { 29 String response_time = data.getStringExtra("response_time"); 30 String response_content = data.getStringExtra("response_content"); 31 String desc = String.format("收到返回消息:\n应答时间为%s\n应答内容为%s", 32 response_time, response_content); 33 tv_request.setText(desc); 34 } 35 } 36 37 }
1 public class ActResponseActivity extends AppCompatActivity implements OnClickListener { 2 3 private EditText et_response; 4 private TextView tv_response; 5 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.activity_act_response); 10 findViewById(R.id.btn_act_response).setOnClickListener(this); 11 et_response = (EditText) findViewById(R.id.et_response); 12 tv_response = (TextView) findViewById(R.id.tv_response); 13 14 Bundle bundle = getIntent().getExtras(); 15 String request_time = bundle.getString("request_time"); 16 String request_content = bundle.getString("request_content"); 17 String desc = String.format("收到请求消息:\n请求时间为%s\n请求内容为%s", 18 request_time, request_content); 19 tv_response.setText(desc); 20 } 21 22 @Override 23 public void onClick(View v) { 24 if (v.getId() == R.id.btn_act_response) { 25 Intent intent = new Intent(); 26 Bundle bundle = new Bundle(); 27 bundle.putString("response_time", DateUtil.getNowTime()); 28 bundle.putString("response_content", et_response.getText().toString()); 29 intent.putExtras(bundle); 30 setResult(Activity.RESULT_OK, intent); 31 finish(); 32 } 33 } 34 35 }
以上是关于Android 开发笔记___Intent的使用的主要内容,如果未能解决你的问题,请参考以下文章
ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER003_播放mp3