之前讲过Servlet的生命周期。Servlet的生命周期相对来讲比较少,一共就那么几个方法。Activity的生命周期相对来讲还是比较多的。

An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup). There are two methods almost all subclasses of Activity will implement: 

正是因为有了这个窗口,就涉及到有的时候这个窗口会显示出来,有的时候这个窗口会隐藏起来。有的时候这个东西会彻底的销毁,这个时候我当前的Activity就会处于一个不同的状态。怎么知道我Activity状态之间进行切换?实际上它就是通过生命周期方法的方式来表示状态的一些变化。

整个Activity它主要处于如下四种状态:

An activity has essentially four states:

    If an activity in the foreground of the screen (at the top of the stack), it is active or running. 

运行或者激活的状态,这个时候Activity处于前台。这就是一个处于前台的Activity。


If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations. 

如果这个东西可以看见但是不能被操作,可见但是不能被操作。这个时候它属于一个paused暂停的状态。paused activity是完全活着的。只有当系统的内存极其紧张的时候,才可能把这个处于暂停状态的activity给它干掉。

但是暂停状态不是太常见。大部分情况咱们使用各种应用的时候很少会出现说可见但是不能被操作的。有些极端的情况比如咱们可以给它创建一个窗口形式的Activity,这个Activity并不是铺满整个屏幕的,它是一个窗口。这个时候它下面的Activity并不是完全被挡住,有一部分是可以被看见的。这个时候它就处于一个暂停的状态。

还有我可以把当前的应用变成一个透明的应用。我在一个应用上面get另外一个应用,这个应用是透明的。也就是说整个的界面是完全透明,可以看见下载。这个时候我后面的应用就处于暂停的状态。


If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.

如果一个Activity完全被另外一个Activity挡住了,处于停止的状态stop。停止状态的Activity完全被另外一个Activity挡住,不被用户看到也不能被操作。


If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.

最后一个就是属于销毁状态了。系统可以把当前的Activity drop丢掉了为了节省内存,把Activity干掉呢调它的finish方法或者把它的进程都杀掉。


就是通过生命周期这些方法来获得不同状态的。

生命周期方法有这么一个图。一共有这么几个。

14_activity四种状态说明的更多相关文章

  1. >hibernate的四种状态

    hibernate的四种状态 1.临时状态 与数据库中没有相对应的数据,也不在session的管理之中,一般是新new出来的对象 2.持久化状态 对象在session的管理中,最后会在事务提交后,在数 ...

  2. Hibernate的session缓存和对象的四种状态

    一.session缓存 说session缓存就得说到JAVA对象的生命周期,当没有任何引用指向一个对象时,对象则可以被gc回收,也就是生命周期结束了 而hibernate获取一个对象后,会将对象存入s ...

  3. a链接的四种状态

    四种状态:hover.link.active.visible a:link{color:#fff;} a链接初始化 a:hover{color:yellow;} 把鼠标放上去的状况 a:active{ ...

  4. java线程四种状态

    一个线程可以有四种状态: 1.新(new), 即线程刚刚创建,而并未执行 2.可运行(runnable),意味着一旦时间分片机制有空闲的CPU周期提供给一个线程,那个线程便可立即开始运行.因此,线程可 ...

  5. java核心知识点学习----并发和并行的区别,进程和线程的区别,如何创建线程和线程的四种状态,什么是线程计时器

    多线程并发就像是内功,框架都像是外功,内功不足,外功也难得精要. 1.进程和线程的区别 一个程序至少有一个进程,一个进程至少有一个线程. 用工厂来比喻就是,一个工厂可以生产不同种类的产品,操作系统就是 ...

  6. HTML5样式和列表、CSS链接的四种状态

    一.HTML5样式 1.标签: <style>:样式定义: <link>:资源引用: 2.属性: type="text/css":引入文档类型: rel=& ...

  7. CSS控制a标签链接的四种状态

    /*CSS链接的四种状态 *a:link 普通的.未被访问的链接样式 *a:visited 用户已访问的链接样式 *a:hover 鼠标指针位于链接上方样式 *a:active 链接被点击的时刻样式 ...

  8. Java多线程(4)----线程的四种状态

    与人有生老病死一样,线程也同样要经历开始(等待).运行.挂起和停止四种不同的状态.这四种状态都可以通过Thread类中的方法进行控制.下面给出了Thread类中和这四种状态相关的方法. 1 // 开始 ...

  9. css中按钮的四种状态

    css中按钮有四种状态 1. 普通状态2. hover 鼠标悬停状态3. active 点击状态4. focus 取得焦点状态 .btn:focus{outline:0;} 可以去除按钮或a标签点击后 ...

随机推荐

  1. 【04】emmet系列之编辑器

     [01]emmet系列之基础介绍 [02]emmet系列之HTML语法 [03]emmet系列之CSS语法 [04]emmet系列之编辑器 [05]emmet系列之各种缩写 前端开发人员,常用的是s ...

  2. Android : reletive layout

    在兄弟的上下左右: android:layout_toRightOf="@id/btn1"/> android:layout_toLeftOf="@id/img1& ...

  3. [luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)

    传送门 BZOJ上是权限题,洛谷赞啊. 求区间 K 大数很简单. 但是如果修改某个数的话,那么就得把这个数及后面所建的主席树都更新一遍 nlogn,显然不行. 所以可以在外面套一个树状数组来优化,树状 ...

  4. 姓名与ID(codevs 1027 未结题)

    题目描述 Description 有N个人,各自有一个姓名和ID(别名).每个人的姓名和ID都没有重复.这些人依次进入一间房间,然后可能会离开.过程中可以得到一些信息,告知在房间里的某个人的ID.你的 ...

  5. android listVIew实现button按钮监听程序

    1.重写simpleAdapter 方法@Override public HashMap<String,String> getItem(int position) { // TODO Au ...

  6. POJ 2456_Aggressive cows

    题意: 给定N个位置,把C头牛分别放入,求相邻两头牛的最大距离. 分析: 即为求两头牛之间最小距离的最大值.二分搜索答案. 代码: #include<iostream> #include& ...

  7. Eclipse替换find/Replace

    使用快捷键:ctrl+F       replaceAll

  8. Dubbo 2.7.1 踩坑记

    Dubbo 2.7 版本增加新特性,新系统开始使用 Dubbo 2.7.1 尝鲜新功能.使用过程中不慎踩到这个版本的 Bug. 系统架构 Spring Boot 2.14-Release + Dubb ...

  9. Servlet的过滤器(Filter)

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/writing-filters.html: Servlet过滤器是Java类,可用于Servlet ...

  10. Check ini style config tool

    INI style config is like below [section] # comment key = value Sometimes we want to check the config ...