Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android官方文檔翻譯 十六 4.Managing the Activity Lifecycle

Android官方文檔翻譯 十六 4.Managing the Activity Lifecycle

編輯:關於Android編程

Managing the Activity Lifecycle

管理activity的生命周期

Dependencies and prerequisites

依賴關系和先決條件

How to create an Android project (see Creating an Android Project)

如何創建一個Android項目(請看Creating an Android Project)


You should also read
你還需要閱讀 Activities

As a user navigates through, out of, and back to your app, the Activity instances in your app transition between different states in their lifecycle. For instance, when your activity starts for the first time, it comes to the foreground of the system and receives user focus. 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. 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第一次開啟的時候,它會出現在你系統的前台並且可以接受用戶的焦點。在這個過程中,Android系統會調用activity中一系列的生命周期方法,那裡有你設置的用戶界面以及其它的一些組件。如果用戶執行了一個動作來開啟另一個activity或者選擇了另一個應用程序,系統會在你的應用程序進入後台的時候調用你的activity中的其它的一些生命周期方法(此時activity不再可見,但是實體和它的狀態依然保持完整)。

Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the 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.

當用戶離開或者再次進入一個activity時,你可以在生命周期回調方法中,生命你的activity應該如何運轉。例如:如果你創建了一個流媒體播放器,當用戶選擇調到另一個應用程序中,你可能需要暫停視頻播放並且結束網絡連接。當用戶重新返回的時候,你可能要再次連接網絡並且允許用戶從原來的節點從新開始播放視頻。

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.

這節課會解釋對於每個activity實體都會接收的重要的生命周期回調方法,還有你要如何使用它們去讓你的activity做用戶期待它做的事情,以及當你的activity不需要它們的時候怎樣才不會消耗系統資源。

Lessons

課程

Starting an Activity

開啟一個activity

Learn the basics about the activity lifecycle, how the user can launch your app, and how to perform basic activity creation.

學習關於生命周期的基礎,如何讓用戶啟動你的應用程序以及如何執行基本的activity創建。

Pausing and Resuming an Activity

暫停和恢復一個activity

Learn what happens when your activity is paused (partially obscured) and resumed and what you should do during these state changes.

學習當activity暫停(局部隱藏)和恢復的時候會發生什麼,以及在這些狀態改變期間你應該做什麼。

Stopping and Restarting an Activity

停止和重啟一個activity

Learn what happens when the user completely leaves your activity and returns to it.

學習當用戶完全離開以及重新返回你的activity的時候會發生什麼。

Recreating an Activity

重新創建一個activity

Learn what happens when your activity is destroyed and how you can rebuild the activity state when necessary.

學習當activity被銷毀的時候會發生什麼,還有當必要的時候你如何重新構建此activity的狀態。

Get started

讓我們開始吧

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved