`
- 浏览:
60068 次
- 性别:
- 来自:
北京
-
During the life of an activity, the system calls a core set of lifecycle methods in a sequence similar to a step pyramid. That is, each stage of the activity 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 the point 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 activity state back down the pyramid in order to dismantle the activity. In some cases, the activity will move only part way down the pyramid and wait (such as when the user switches to another app), from which point the activity can move back to the top (if the user returns to the activity) and resume where the user left off.
Depending on the complexity of your activity, you probably don't need to implement all the lifecycle methods. However, it's important that you understand each one and implement those that ensure your app behaves the way users expect. Implementing your activity lifecycle methods properly ensures your app behaves well in several ways, including that it:
Does not crash if the user receives a phone call or switches to another app while using your app.
Does not consume valuable system resources when the user is not actively using it.
Does not lose the user's progress if they leave your app and return to it at a later time.
Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation.
As you'll learn in the following lessons, there are several situations in which an activity transitions between different states that are illustrated in figure 1. However, only three of these states can be static. That is, the activity can exist in one of only three states for an extended period of time:
Resumed
In this state, the activity is in the foreground and the user can interact with it. (Also sometimes referred to as the "running" state.)
Paused
In this state, the activity is partially obscured by another activity—the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen. The paused activity does not receive user input and cannot execute any code.
Stopped
In this state, the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.
The other states (Created and Started) are transient and the system quickly moves from them to the next state by calling the next lifecycle callback method. That is, after the system calls onCreate(), it quickly calls onStart(), which is quickly followed by onResume().
- 大小: 47.6 KB
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
android 不同activity切换时它们的回调函数调用逻辑的研究
Activity与Fragment通过接口回调进行通信
生命周期回调函数的执行顺序。建议下载本资源的同修们,将activity的生命周期与fragment的生命周期联系起来学习使用。
activity的回调:根据请求码和结果码获取intent中携带的数据
回调函数 就像activities一样,fragments也有它们自己的生命周期。理解fragments的生命周期,可以使你在它们被销毁的时候保存它们的实例,这样在它们重新被创建的时候,就能恢复它们之前的状态。 流程: onAttach()...
Activity添加 含有一个Fragment ,Fragment中listView 单项选择,通过回调的方式 告诉Activity当前选择哪个城市
用于测试Activity创建和销毁时,Activity状态的保存和销毁
刚刚写的一段Android的Intent的代码,实现连个Activity之间的跳转。
android startActivityForResult实现Acitvity的回调 最常见的登录运用.
方法回调是功能定义和功能分离的一种手段,是一种松耦合的设计思想。在JAVA中回调是通过接口来实现的。作为一种系统架构,必须要有自己的运行环境,并且要提供用户的实现接口。 下面通过实例来模拟一下Android中...
测试Activity的7个周期函数,以及在由一个Activity跳转到另外一个Activity的过程中,各个周期函数的变化
fragment与activity的简单通信会回调,没图片和其他
aidl双向通信,Service加回调刷新自身Activity
inline-activity-result,在回调中内联接收活动结果,不带任何样板文件。.zip
仿网易贴吧对activity的状态进行保存
本代码为android学习初步的activity转换,已在win7下调试通过
在Android内实现各个Activity之间的转换
Activity 的生命周期 以及 横屏竖屏切换时 Activity 的状态变化 例如: 切换到横屏 onSaveInstanceState onPause onStop onDestroy onCreate onStart onRestoreInstanceState onResume