android四大组件之activity
activity生命周期
onCreate -> onStart -> onResume -> onPause -> onStop -> onDestroy
点击运行
onCreate -> onStart -> onResuem
点击home键
onPause -> onStop
再回到activity1界面
onRestart -> onStart -> onResume
点返回键
onPause -> onStop -> onDestroy
点击跳转 activity1-> activity2
onPause -> onCreate2 -> onStart2 -> onResume2 -> onStop
再按返回键
onPause2 -> onRestart -> onStart -> onResume -> onStop2 -> onDestroy2
两个activity的跳转
Intent intent = new Intent(MainActivity.this,Activity2.class);
startActivity(intent);
ComponentName cn = new ComponentName(this,Activity2.class);
Intent intent = new Intent();
intent.setComponentName(cn);
startActivity(intent);
Intent intent = new Intent();
intent.setClassName("com.example.myapplication","com.example.myapplication.Activity2")
startActivity(intent);
方法四
<!先在manifest文件中配置好MainActivity的配置文件>
<activity
android:name=".MainActivity2"
android:exported="false" >
<intent-filter>
<action android:name="MainActivity2"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Intent intent = new Intent();
intent.setAction("MainActivity2");
startActivity(intent);
|