1. 程式人生 > >Android fundamentals 02.2: Activity lifecycle and state

Android fundamentals 02.2: Activity lifecycle and state

onSaveInstanceState()和onRestoreInstanceState()的使用時機
#在執行螢幕方向切換的操作時用到上述兩個方法來儲存和恢復資料 1.

lifecycle如下:
onCreate()->onStart()->onResume->切換螢幕方向操作->onPause()->
onSaveInstanceState()->onStop()->onDestory()->onCreate()->onStart()->
onRestoreInstanceState()->onResume()

2.最近使用過的應用切換,不影響介面效果。
3.按home鍵,從最近使用過應用進入或者從主介面圖示進入應用,不影響介面效果。
lifecycle如下:
onPause()->onSaveInstanceState()->onStop()->
再次進入應用->onRstart()->onStart()->onResume().