Intent intent = new Intent(MainActivity.this,SecondActivity.class);startActivity(intent);
Intent intent2 = new Intent("com.example.intenttest.ACTION_START");intent2.addCategory("com.example.intenttest.MY_CATEGORY");startActivity(intent);
<activityandroid:name=".SecondActivity"android:label="@string/app_name"><intent-filter ><action android:name="com.example.intenttest.ACTION_START"/><category android:name="android.intent.category.DEFAULT"/><category android:name="com.example.intenttest.MY_CATEGORY"/></intent-filter></activity>
Intent intent = new Intent(MainActivity.this,SecondActivity.class);startActivityForResult(intent,1);
Intent intent = new Intent();intent.putExtra("extra_data", "我返回数据了");setResult(RESULT_OK, intent);finish();
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {switch (requestCode) {case 1:if(RESULT_OK == resultCode){String extra_data = data.getStringExtra("extra_data");Log.i("extra_data",extra_data);}break;default:break;}};

public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);Log.i("Life Tag", "OnCreate");Button normalButton = (Button)findViewById(R.id.normal_button);Button dialogButton = (Button)findViewById(R.id.dialog_button);EditText tempText = (EditText)findViewById(R.id.login_name);if(null != savedInstanceState){//利用Bundle对象来还原之前在内存回收活动时,保存的关键数据String tempData = savedInstanceState.getString("tempName");Log.i("Tag", tempData);tempText.setText(tempData);}//测试安卓活动的七个生命周期,利用对话框活动和完全覆盖活动来区别onPause和onStop方法normalButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(MainActivity.this,NormalActivity.class);startActivity(intent);}});dialogButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(MainActivity.this,DialogActivity.class);startActivity(intent);}});}@Overrideprotected void onStart() {// TODO Auto-generated method stubsuper.onStart();Log.i("Life Tag", "onStart");}@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();Log.i("Life Tag", "OnResume");}@Overrideprotected void onPause() {// TODO Auto-generated method stubsuper.onPause();Log.i("Life Tag", "OnPause");}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();Log.i("Life Tag", "onStop");}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();Log.i("Life Tag", "onDestroy");}@Overrideprotected void onRestart() {// TODO Auto-generated method stubsuper.onRestart();Log.i("Life Tag", "OnRestart");}//在内存不足时回收活动,保存其主要关键数据,这在用户体验还是比较重要的了。@Overrideprotected void onSaveInstanceState(Bundle outState) {// TODO Auto-generated method stubsuper.onSaveInstanceState(outState);EditText tempText = (EditText)findViewById(R.id.login_name);String name = tempText.getText().toString();outState.putString("tempName", name);Log.i("Name_Tag", name);}

protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button secondButton = (Button)findViewById(R.id.secondButton);Log.i("TAG", "The task is"+getTaskId());secondButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(MainActivity.this,SecondActivity.class);startActivity(intent);}});}
protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_second);Log.i("TAG", "The task is"+getTaskId());Button thirdButton = (Button)findViewById(R.id.third_button);thirdButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(SecondActivity.this,ThirdActivity.class);startActivity(intent);}});}}
protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_third);Log.i("TAG", "The task is"+getTaskId());Button firstButton = (Button)findViewById(R.id.firstButton);firstButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(ThirdActivity.this,MainActivity.class);startActivity(intent);}});}}

原文:http://www.cnblogs.com/kamzhuyuqing/p/415e629929034c94cca64b75892ed479.html