Understanding the Android Life Cycle
Problem
Android apps do not have a “main” method; you need to learn how they get started and how they stop or get stopped.
Solution
The class android.Activity provides a number of well-defined life-cycle methods that are called when an application is started, suspended, restarted, and so on, as well as a method you can call to mark an activity as finished.
Discussion
Your Android application runs in its own Unix process, so in general it cannot directly affect any other running application. The Dalvik VM interfaces with the operating system to call you when your application starts, when the user switches to another application, and so on. There is a well-defined life cycle for Android applications.
An Android application has three states it can be in:
• Active, in which the app is visible to the user and is running
• Paused, in which the app is partly obscured and has lost the input focus
• Stopped, in which the app is completely hidden from view
Your app will be transitioned among these states by Android calling the following methods on the current activity at the appropriate time:
void onCreate(Bundle savedInstanceState)
void onStart()
void onResume()
void onRestart()
void onPause()
void onStop()
void onDestroy()

For an application’s first activity, onCreate() is how you know that the application has been started. This is where you normally do constructor-like work such as setting up the “main window” with setContentView(), adding listeners to buttons to do work (including starting additional activities), and so on. This is the one method that even the simplest Android app needs.
You can see the effects of the various life cycle methods by creating a dummy project in Eclipse and overriding all the methods with log “debug” statements.
Understanding the Android Life Cycle的更多相关文章
- 北京联想招聘-Android Framework高级工程师(7-10年) 加入qq 群:220486180 或者直接在此 留言咨询
Job ID #: 45038 Position Title: Android Framework高级工程师 Location: CHN-Beijing Functional Area: Resear ...
- Android progressbar 详解
[原文Android学习笔记(十六)进度条] ProgressBar XML属性 属性名 描述 android:animationResolution 超时的动画帧之间的毫秒 :必须是一个整数值,如“ ...
- Android推送技术研究
前言 最近研究Android推送的实现, 研究了两天一夜, 有了一点收获, 写下来既为了分享, 也为了吐槽. 需要说明的是有些东西偏底层硬件和通信行业, 我对这些一窍不通, 只能说说自己的理解. 为什 ...
- Android 开发 VectorDrawable 矢量图 (三)矢量图动画
VectorDrawable 矢量图 三部曲: Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图 Android 开发 VectorDrawabl ...
- Android File Hierarchy : System Structure Architecture Layout
Most of the Android user are using their Android phone just for calls, SMS, browsing and basic apps, ...
- 解读 Android TTS 语音合成播报
随着从事 Android 开发年限增加,负责的工作项目也从应用层开发逐步过渡到 Android Framework 层开发.虽然一开始就知道 Android 知识体系的庞大,但是当你逐渐从 Appli ...
- web forms page和control的生命周期life cycle交互,以及page生命周期中每个event中需要做什么事情
只有 page_load和page_init这些可以autoeventwireup RenderControl只提供override public override void RenderContro ...
- Android Service Summary
In the Androird, service is a none-UI background process that is doing some specific jobs. 6.1 Ex ...
- android progressbar 自定义图片匀速旋转
项目中需要使用圆形进度条进行数据加载的显示,所以需要两个步骤 1:自定义progressbar滚动图片 2:匀速旋转图片 步骤一:自定义progressbar图片 <ProgressBar an ...
随机推荐
- yii2 控制器里 action 大小写组合造成的路由问题
yii1中, 若存在如下控制器 class BindController extends CController { public function actionGetMobilePhone () { ...
- Linux shell入门基础(五)
五.bash运算及启动脚本 01.使用bash的命令历史 #history …… #set(显示所有的变量) | grep HIS HISTFILE=/root/.bash_history HISTF ...
- 格雷码(Gray Code)转二进制码(Binary Code)
学习verilog generate语句时,偶然看到用generate语句来进行格雷码到二进制码转换的代码,就从网上找了一些案例来学习. 下表为几种自然二进制码与格雷码的对照表: 十进制数 自然二进制 ...
- codevs 3332 数列 (矩阵乘法)
/* 裸地矩阵乘法 矩阵很好想的 1 1 0 0 0 1 1 0 0 */ #include<iostream> #include<cstring> #include<c ...
- .net框架介绍
.net 一般指 .net Framework框架,是一种平台,一种技术 C# 是一种编程语言,可以开发基于.net平台的应用 Java 既是一种技术,也是一种语言 .net可以开发桌面应用程序 ...
- js的new操作符
1.创建一个空对象,并且 this 变量引用该对象,同时还继承了该函数的原型. 2.属性和方法被加入到 this 引用的对象中. 3.新创建的对象由 this 所引用,并且最后隐式的返回 this . ...
- Char Varchar Nvarchar区别
char和varchar是一样的字符型,不同在于,varchar比char更灵活,精确,且不占内存空间,当你取同样的字符时,char会在该字符后面加上空格,而varchar则只取得这个字符,比如有字段 ...
- Landsat元数据批量下载工具
目录 前言 landsat数据情况简介 下载元数据 总结 一.前言 最近由于工作需要,需要下载部分landsat数据的元数据,老板大手一挥,给了十几年的landsat的path.row以 ...
- linux网络编程常用头文件
sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...
- uva 1378 A Funny Stone Game (博弈-SG)
题目链接:http://vjudge.net/problem/viewProblem.action?id=41555 把第i堆的每个石子看出一堆个数为n-i的石子,转换为组合游戏 #include & ...