Android相关整理系列-基础知识篇

Android相关整理系列

基础知识篇

1.Activity生命周期

1>启动过程: onCreate->onStart->onResume

02-23 12:00:24.998 10574-10574/? E/MainActivity: onCreate

02-23 12:00:24.998 10574-10574/? E/MainActivity: onStart

02-23 12:00:25.002 10574-10574/? E/MainActivity: onResume

2>销毁过程:onPause->onStop->onDestory

02-23 12:02:28.477 10574-10574/? E/MainActivity: onPause

02-23 12:02:28.867 10574-10574/? E/MainActivity: onStop

02-23 12:02:28.867 10574-10574/? E/MainActivity: onDestroy

3>退到后台过程: onPause->onStop

02-23 12:06:46.523 10574-10574/? E/MainActivity: onPause

02-23 12:06:46.540 10574-10574/? E/MainActivity: onStop

4>回到前台过程:onStart->onResume

02-23 12:08:31.161 10574-10574/? E/MainActivity: onStart

02-23 12:08:31.162 10574-10574/? E/MainActivity: onResume

5>自动被系统销毁的过程: onPause-> onSaveInstanceState-> onStop-onDestroy

02-23 14:12:22.917 18626-18626/com.example.zhujian.myapplication E/MainActivity: onPause

02-23 14:12:22.926 18626-18626/com.example.zhujian.myapplication E/MainActivity: onSaveInstanceState

02-23 14:12:22.936 18626-18626/com.example.zhujian.myapplication E/MainActivity: onStop

02-23 14:12:23.020 18626-18626/com.example.zhujian.myapplication E/MainActivity: onDestroy

6>被系统销毁后再次启动过程onCreate(可以获取onSaveInstanceState的值)-> onStart-> onResume

02-23 14:14:25.039 21418-21418/com.example.zhujian.myapplication E/MainActivity: onCreate

02-23 14:14:25.039 21418-21418/com.example.zhujian.myapplication E/MainActivity: onCreate->savedInstanceState:1

02-23 14:14:25.040 21418-21418/com.example.zhujian.myapplication E/MainActivity: onStart

02-23 14:14:25.045 21418-21418/com.example.zhujian.myapplication E/MainActivity: onResume

2. Service的生命周期

  1>第一次启动过程onCreate-> onStartCommand

  02-23 15:31:11.822 29063-29063/com.example.zhujian.myapplication E/MyService: onCreate

  02-23 15:31:11.843 29063-29063/com.example.zhujian.myapplication E/MyService: onStartCommand

  2>重复启动过程onStartCommand

  02-23 15:31:24.327 29063-29063/com.example.zhujian.myapplication E/MyService: onStartCommand

  3>自停止过程onDestroy

  02-23 15:34:20.252 29063-29063/com.example.zhujian.myapplication E/MyService: onDestroy

  4>国产手机后台kill进程,不能监控到onDestroy

  5>自动被系统杀掉的过程(不保留后台活动模拟)

    Service不会被杀

  6>初次bindService的过程 onCreate-> onBind ->onServiceConnected

    02-23 17:17:42.576 25290-25290/com.example.zhujian.myapplication E/MyService: onCreate

02-23 17:17:42.577 25290-25290/ com.example.zhujian.myapplication E/MyService: onBind

02-23 17:17:42.582 25290-25290/com.example.zhujian.myapplication E/MainActivity: onServiceConnectedcom.example.zhujian.myapplication.MyService-2032822464

7>重复bindService过程 onBind 不会重复执行

8>无启动startService动作(即无onStartCommand执行)的unbindService过程 onUnbind-> onDestroy

  02-23 17:22:04.359 25290-25290/com.example.zhujian.myapplication E/MyService: onUnbind

  02-23 17:22:04.359 25290-25290/com.example.zhujian.myapplication E/MyService: onDestroy

  9>有启动startService动作的unbindService过程,只有onUnbind,不会执行onDestroy

    02-23 17:23:58.888 25290-25290/com.example.zhujian.myapplication E/MyService: onUnbind

10>另外onServiceDisConnected只会在Service丢失时才会调用,unbindService时不会执行

你可能感兴趣的:(Android相关整理系列-基础知识篇)