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

让我们开始吧

这是我自己翻译的,如果您发现其中有重要错误,敬请指出,万分感谢!

Android官方文档翻译 十六 4.Managing the Activity Lifecycle的更多相关文章

  1. Android官方文档翻译 十五 3.3Supporting Different Platform Versions

    Supporting Different Platform Versions 支持不同的平台版本 This lesson teaches you to 这节课教给你 Specify Minimum a ...

  2. Android官方文档翻译 十四 3.2Supporting Different Screens

    Supporting Different Screens 支持不同的屏幕 This lesson teaches you to 这节课教给你 Create Different Layouts 创建不同 ...

  3. Android官方文档翻译 十二 3.Supporting Different Devices

    Supporting Different Devices 支持不同设备 Dependencies and prerequisites 依赖关系和先决条件 Android 1.6 or higher A ...

  4. Android官方文档翻译 十 2.3Styling the Action Bar

    Styling the Action Bar 设计菜单栏的样式 This lesson teaches you to 这节课教给你 Use an Android Theme 使用一个Android主题 ...

  5. Android官方文档翻译 十八 4.2Pausing and Resuming an Activity

    Pausing and Resuming an Activity 暂停和恢复一个activity This lesson teaches you to 这节课教给你 Pause Your Activi ...

  6. Android官方文档翻译 一 Getting Started

    Getting Started 让我们开始吧! Welcome to Training for Android developers. 欢迎来到Android开发者训练营. Here you'll f ...

  7. Android官方文档翻译 六 1.4Starting Another Activity

    Starting Another Activity 开启另一个Activity This lesson teaches you to 这节课教给你: Respond to the Send Butto ...

  8. android官方文档翻译(不断更新中。。。)

    最近在自学android,抽空把官方文档的guide跟training差不多看了一遍,又对比了一些书籍,感觉还是官方文档讲得比较好,所以自己计划把官方文档翻译一下,方便自己的知识巩固以及复习查找,由于 ...

  9. Android官方文档翻译 十七 4.1Starting an Activity

    Starting an Activity 开启一个Activity This lesson teaches you to 这节课教给你 Understand the Lifecycle Callbac ...

随机推荐

  1. 资源工作表中与资源有关的操作(Project)

    <Project2016 企业项目管理实践>张会斌 董方好 编著 这个内容,我需要专门写一篇吗? 不写吧,好像对不起我那股学习的劲:写吧,实在是--一句话就够了:所有与任务有关的新建.修改 ...

  2. [源码解析] PyTorch 分布式(18) --- 使用 RPC 的分布式管道并行

    [源码解析] PyTorch 分布式(18) --- 使用 RPC 的分布式管道并行 目录 [源码解析] PyTorch 分布式(18) --- 使用 RPC 的分布式管道并行 0x00 摘要 0x0 ...

  3. 深刨显式锁ReentrantLock原理及其与内置锁的区别,以及读写锁ReentrantReadWriteLock使用场景

    13.显示锁 在Java5.0之前,在协调对共享对象的访问时可以使用的机制只有synchronized和volatile.Java5.0增加了一种新的机制:ReentrantLock.与之前提到过的机 ...

  4. CF19A World Football Cup 题解

    Content 有 \(n\) 个球队参加一场足球比赛,比赛排名前 \(\dfrac{n}{2}\) 的队伍将会进入下一轮的淘汰赛.比赛将会打 \(\dfrac{n(n-1)}{2}\) 场,胜者得 ...

  5. libevent源码学习(2):内存管理

    目录 内存管理函数 函数声明 event-config.h 函数定义 event_mm_malloc_ event_mm_calloc_ event_mm_strdup_ event_mm_reall ...

  6. PSpice基本仿真分析例程

    一.瞬态分析 二.直流分析 2.1.直流分析电路 2.2.直流分析配置 2.3.直流分析输出波形 受供电电源的限制,输出最大值为±15V. 三.交流分析 3.1.1.交流分析电路1 3.1.1.交流分 ...

  7. 10-2 bonding

    创建bonding设备的配置文件 centos8 /etc/sysconfig/network-scripts/ifcfg-bond0 NAME=bond0 TYPE=bond DEVICE=bond ...

  8. 【LeetCode】566. Reshape the Matrix 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 变长数组 求余法 维护行列 相似题目 参考资料 日期 ...

  9. 在线编辑Word——插入图片、图形

    在Word中支持插入图片.图形等元素,同时支持对插入的图片和图形进行格式化操作,如裁剪.调整尺寸大小.调成颜色.阴影.倾斜角度.透明度等等.本文,将通过使用Spire.Cloud Word在线编辑器来 ...

  10. uniapp云打包之后华为手机推送角标不显示(有推送没角标)

    小米手机上有角标,华为和OPPO没有角标 解决方法: 华为手机添加权限(可通过反编译或者离线打包添加) < uses - permission android:name="com.hu ...