1,mainActivity.java java
Intent intent = new Intent(add_task.this, sortlist_java.class); startActivityForResult(intent,0);0表明請求碼,用來標誌請求方的符號。
2,在請求java文件裏面重寫onActivityResults方法 ide
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // super.onActivityResult(requestCode, resultCode, data); et1=(EditText)findViewById(R.id.sortEdit); //分類文本框 et5=(EditText)findViewById(R.id.remarkEdit);//備註文本框 if (requestCode == 0 && resultCode == 0) { String resultsort = data.getStringExtra("sort"); et1.setText(resultsort); } //備註值 if (requestCode == 3 && resultCode == 3){ String result=data.getStringExtra("remark"); Toast.makeText(add_task.this,result,Toast.LENGTH_LONG).show(); et5.setText(result); } }3,,請求須要返回數據的界面.java
//確認按鈕返回給add_task文本框的值 ib1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String editstring = et1.getText().toString(); Intent intent = getIntent(); Bundle data = new Bundle(); data.putString("sort", editstring); intent.putExtras(data); sortlist_java.this.setResult(0, intent); sortlist_java.this.finish(); } });