onCreate(建立) 、onStart(激活) 、onResume(恢復) 、onPause(暫停) 、onStop(中止) 、onDestroy(銷燬) 、onRestart(重啓)。 app
Activity starts -->onCreate()-->onStart()-->onResume()-->activity is running--another activity comes in front of this activity-->onPause()--the activity is no longer visivble-->onStop()-->onDestroy()-->activity is shut down 函數
notes: 佈局
When the 「onPause()「excute,other applications need memory ,then Process is killed(User navigates back to activity),last excute onCreate()。 this
When the 「onPause()「excute,the activity comes to the foreground,so it will excute onRestart(),last excute onstart()。 spa
各個函數使用的時間: ci
一、onCreate()
Acitivity首次建立時被調用。用於設置Acitivity的佈局文件,綁定按鈕監聽器等一些普通靜態操做。
二、onStart()
Acitivity對用戶可見時被調用。
三、onResume()
Acitivity得到用戶焦點,即用戶可操做該Acitivity時被調用。
四、onPause()
應用程序啓動了其它Acitivity時被調用。通常用於保存當前Acitivity中的數據。
五、onStop()
Acitivity不可見時被調用。
六、onRestart()
已中止的Acitivity從新啓動時被調用。
七、onDestroy()
調用Acitivity的finish()方法或Android系統資源不足時被調用。 資源