管理Activity的生命週期

As a user navigates through, out of, and back to your app, the Activity instances in your app transition between different states in their life cycle.前端

做爲一個用戶經過導航進出和回到你的應用程序的這個過程當中,你應用程序的Activity實例在它的生命週期的不一樣狀態之間轉換。網絡

For instance, when your activity starts for the first time, it comes to the foreground of the system and receives user focus.app

例如:當你的Activity第一次啓動時,它會出如今系統的最前端並接受用戶的焦點。ide

During this process, the Android system calls a series of lifecycle methods on the activity in which you set up the user interface and other components.ui

在這個過程當中,Android系統調用了Activity一系列的生命週期方法,在這些方法中你能夠設置用戶界面和其餘組件。this

If the user performs an action that starts another activity or switches to another app, the system calls another set of lifecycle methods on your activity as it moves into the background (where the activity is no longer visible, but the instance and its state remains intact).翻譯

若是用戶執行一個動做去啓動其餘的Activity或者切換到另外一個應用程序,隨着當前Activity移動進後臺,系統會調用另外一組生命週期方法。(這裏的Activity再也不是可見的,可是它的實例和它的狀態依然保持不變)component

Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity.orm

在生命週期的回調方法中,你能夠聲明Activity在用戶離開以及從新進入Activity時的一些行爲。視頻

For example, if you're building a streaming video player, you might pause the video and terminate the network connection when the user switches to another app. 

例如,若是你正在構建一個流媒體播放器,在用戶切換到另外一個應用程序時,你可能會暫停視頻和中止此次的網絡連接。

When the user returns, you can reconnect to the network and allow the user to resume the video from the same spot.

當用戶返回時,你能夠從新鏈接網絡並容許用戶恢復到以前同一點的視頻。

This class explains important lifecycle callback methods that each Activity instance receives and how you can use them so your activity does what the user expects and does not consume system resources when your activity doesn't need them.

這一課闡述了生命週期回調方法的重要性。(好吧接下來不會翻譯了。)

相關文章
相關標籤/搜索