Starting an Activity

Unlike other programming paradigms in which apps are launched with amain() method, theAndroid system initiates code in an Activity instance by invoking specificcallback methods that correspond to specific stages of itslifecycle. There is a sequence of callback methods that start up an activity and a sequence ofcallback methods that tear down an activity.

其他编程范例是通过调用主函数方法启动的,而安卓系统启动代码却与他们不同:在活动实例中,在不同的生命周期阶段会调用特定的回调方法,它具有一系列的开始和销毁活动的回调方法。

This lesson provides an overview of the most important lifecycle methods and shows you how tohandle the first lifecycle callback that creates a new instance of your activity.

下面概述最重要的生命周期方法,并演示如何运用第一次生命周期的会回调函数创建一个新的活动实例。


Understand the Lifecycle Callbacks

(理解生命周期回调)

During the life of an activity, the system calls a core set of lifecycle methods ina sequence similar to a step pyramid. That is, each stage of theactivity lifecycle is a separate step on the pyramid. As the system creates a new activity instance,each callback method moves the activity state one step toward the top. The top of the pyramid is thepoint at which the activity is running in the foreground and the user can interact with it.

在活动的生命中,系统调用一系列的核心生命周期方法,这些方法的序列类似于金字塔,且活动周期的每个阶段在金字塔上都是独立的。当系统创建一个活动实例时,回调方法被逐级调用,最后活动状态达到金字塔顶端,该活动状态就是前台运行,也用户与之交互的状态。

As the user begins to leave the activity, the system calls other methods that move the activitystate back down the pyramid in order to dismantle the activity. In some cases, the activity willmove only part way down the pyramid and wait (such as when the user switches to another app), fromwhich point the activity can move back to the top (if the user returns to the activity) andresume where the user left off.

当用户开始离开活动时,系统会调用其他方法撤销该活动。在某些例子中,活动将部分的离开金字塔顶端状态并且等待(比如:当用户切换到其他应用程序),活动能够回到顶端状态(如果用户重新返回到该活动)并且恢复到离开时的状态。




更多相关文章

  1. 仿照DatePickerFragment实现的TimePickerFragment
  2. 探索FragmentTransaction#commit()抛出IllegalStateException
  3. Android学习笔记-Android初级 (二)
  4. Android(安卓)Retrofit2网路编程实现方法详解
  5. Android存储登陆信息
  6. Android移动应用知识点总汇①
  7. Activity的基本理解
  8. Android(安卓)StudioRecyclerView,fragment,adapter的用法
  9. Android关于在Canvas类里的绘制线程问题汇总

随机推荐

  1. Android之R文件
  2. android背景选择器selected
  3. Android(安卓)Sample NotePad学习一
  4. Android中自定义带图标和清空内容按钮的E
  5. Android(安卓)Studio中获取MD5、SHA1、SH
  6. 下载各个版本SDK Tools及ADT的技巧
  7. Android(安卓)之Google认证GMS详细解剖
  8. Android(安卓)开机自启动应用
  9. 2011.09.15 ——— android 桌面添加快捷
  10. 新浪微博Android客户端学习记录四:完成OAu