刚下班回来,翻译一篇简单的,加深理解。

文档地址:http://guides.codepath.com/android/Activity-Lifecycle#activity-lifecycle

Activity Lifecycle

As a user navigates throughout an app, Android maintains the visited activities in a stack, with the currently visible activity always placed at the top of the stack.

At any point in time a particular activity can be in one of the following 4 states:

当用户浏览一个app,Android的activitys在堆栈中以堆叠形式保持着,当前可见的activity总是位于栈顶

在任何时间的特定活动总会保持下面4中状态之一:

Android学习之Activity生命周期文档翻译_第1张图片

运行状态:活动可见并且可以与用户交互

暂停状态:活动可见,但是不能与用户交互

停止状态:活动不可见

杀死状态:活动已经被系统杀死或者调用了finish()方法

Activity Lifecycle

The following diagram shows the important state paths of an Activity.
The square rectangles represent callback methods you can implement to
perform operations when the Activity moves between states. These are
described further in the table below the diagram.

下面的图展示了活动比较重要的状态路径,你可以去实现长方形里面的回调方法,执行操作时活动在不同状态间的移动,这些在表中图下面做进一步描述

生命周期:oncrete,onstart,onpause,onstop,onrestart,ondestory。

运行状态:在onresume—>onpause之间

杀死状态:在onstop—>ondestory之间

暂停状态:在onpause—>onstop之间

进程被杀死:一般是在onpause,onstop—>oncreate之间

onrestart:在onstop—》onstart之间

Android学习之Activity生命周期文档翻译_第2张图片

onCreate:活动在创建,但是对于用户不可见,用户大部分初始化代码放在这个方法里,通过setContentView来为活动初始化布局

onstart:活动可见,但是还没准备好与用户交互,这个方法并没有用太多,可以注册一个广播来监听影响用户UI的改变,因为这个方法UI已经可见。

没搞过,不太懂?

onresume:活动可见,可以与用户交互,这是一个好的方法来启动动画,打开类似相机的设备

onpause:这个活动已经进入后台,并且停止与用户交互,发生情况是在当前界面启动另外一个活动,通常在这个方法里做保存全局状态,例如写入一个文件

onstop:活动不可见,通常跟onstart中的操作相反。

ondestory:当调用finish(),或者系统需要充足内存就会触发这个方法,通常在这个方法里做各种清除操作,例如活动有一个线程正在后台运行来请求网络数据,它会在oncreate()中创建线程,在ondestory中停止线程

onrestart:再一次启动之前,活动已经被停止。这个方法通常并不需要去实现回调。

更多相关文章

  1. View的invalidate()方法的源码分析
  2. Android沉浸式状态栏三种方式的实现
  3. Android利用反射获取状态栏(StatusBar)高度
  4. Android学习札记36:一个关于onSaveInstanceState ()方法的例子
  5. Android电池状态监听实例1(下)
  6. Google用户登录界面 Android实现
  7. Android 沉浸式状态栏跟虚拟按键冲突问题 隐藏虚拟按键
  8. Android调用系统的发邮件方法
  9. Android轮播图Banner使用方法

随机推荐

  1. [Android]Fragment自定义动画、动画监听
  2. Android IPC 之 AIDL(一)
  3. 针对 Android Web 应用程序的事件记录器E
  4. Java中Textview 在XML中详细配置讲解
  5. android工具之DDMS
  6. Android 手机Root 原理解析
  7. Android开发学习之路--Content Provider
  8. android动态加载jar包中的图片
  9. 关于Android的Crash
  10. android 的Activity和Service之间的通信