1. 简单的Intent使用,仅仅用于Activity直接的跳转
Intent intent = new Intent(); intent.setClass(FileProcessHust.this, MyListActivity.class); startActivity(intent);
static final int REQUEST_CODE = 1;REQUEST_CODE是此次跳转的编号,用于在返回时识别,进行后一步处理。
Intent intent1 = new Intent(ActivityMain.this, Activity1.class); intent1.putExtra("activityMain", "数据来自activityMain"); startActivityForResult(intent1, REQUEST_CODE);
在Activity1里,接受信息,方法如下:
String data=null; Bundle extras = getIntent().getExtras(); if (extras != null) { data = extras.getString("activityMain"); }
Bundle bundle = new Bundle(); bundle.putString("store", "数据来自Activity1"); Intent mIntent = new Intent(); mIntent.putExtras(bundle); setResult(RESULT_OK, mIntent); finish();
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE) { if (resultCode == RESULT_CANCELED) setTitle("取消"); else if (resultCode == RESULT_OK) { String temp=null; Bundle extras = data.getExtras(); if (extras != null) { temp = extras.getString("store"); } setTitle(temp); } } }