Android Activity生命周期的学习以及Logcat的使用
2010-05-31 13:51:00 来源:WEB开发网这说明一般Activity的启动顺序是onCreate -> onStart -> onResume
2. 点击back返回键后
05-08 09:40:04.129: DEBUG/Activity1(313): onPause Activity 1 05-08 09:40:04.628: DEBUG/Activity1(313): onStop Activity 1 05-08 09:40:04.659: DEBUG/Activity1(313): onDestory Activity 1
退出当前Activity时,onPause -> onStop -> onDestory
3. 再次启动Activity
05-08 09:40:18.249: DEBUG/Activity1(313): onCreate Activity 1 05-08 09:40:18.249: DEBUG/Activity1(313): onStart Activity 1 05-08 09:40:18.259: DEBUG/Activity1(313): onResume Activity 1
和一般启动的顺序是一样的
4. 从Activity1启动Acitivity2
05-08 09:40:25.477: DEBUG/Activity1(313): onPause Activity 1 05-08 09:40:25.687: DEBUG/Activity2(313): onCreate Activity 2 05-08 09:40:25.687: DEBUG/Activity2(313): onStart Activity 2 05-08 09:40:25.719: DEBUG/Activity2(313): onResume Activity 2 05-08 09:40:26.277: DEBUG/Activity1(313): onStop Activity 1
Activity1.onPause -> Activity2.onCreate -> Activity2.onStart -> Activity2.onResume ->Activity1.onStop
5. 点击Home键回到桌面
05-08 09:40:31.777: DEBUG/Activity2(313): onPause Activity 2 05-08 09:40:32.658: DEBUG/Activity2(313): onStop Activity 2
Activity2.onPause - > Activity2.onStop
6. 回到原来的程序
05-08 09:40:50.429: INFO/ActivityManager(58): Starting activity: Intent ... 05-08 09:40:50.649: DEBUG/Activity2(313): onRestart Activity 2 05-08 09:40:50.649: DEBUG/Activity2(313): onStart Activity 2 05-08 09:40:50.769: DEBUG/Activity2(313): onResume Activity 2
Activity2.onRestart -> Activity2.onStart -> Activity2.onResume
7. 点击comfirm, setResult(RESULT_OK),Activity2.finish(),返回到Activity1
05-08 09:41:04.928: DEBUG/Activity2(313): onPause Activity 2 05-08 09:41:04.988: DEBUG/Activity1(313): onRestart Activity 1 05-08 09:41:04.998:
更多精彩
赞助商链接