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的更多相关文章

  1. 北京联想招聘-Android Framework高级工程师(7-10年) 加入qq 群:220486180 或者直接在此 留言咨询

    Job ID #: 45038 Position Title: Android Framework高级工程师 Location: CHN-Beijing Functional Area: Resear ...

  2. Android progressbar 详解

    [原文Android学习笔记(十六)进度条] ProgressBar XML属性 属性名 描述 android:animationResolution 超时的动画帧之间的毫秒 :必须是一个整数值,如“ ...

  3. Android推送技术研究

    前言 最近研究Android推送的实现, 研究了两天一夜, 有了一点收获, 写下来既为了分享, 也为了吐槽. 需要说明的是有些东西偏底层硬件和通信行业, 我对这些一窍不通, 只能说说自己的理解. 为什 ...

  4. Android 开发 VectorDrawable 矢量图 (三)矢量图动画

    VectorDrawable 矢量图 三部曲: Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图 Android 开发 VectorDrawabl ...

  5. 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, ...

  6. 解读 Android TTS 语音合成播报

    随着从事 Android 开发年限增加,负责的工作项目也从应用层开发逐步过渡到 Android Framework 层开发.虽然一开始就知道 Android 知识体系的庞大,但是当你逐渐从 Appli ...

  7. web forms page和control的生命周期life cycle交互,以及page生命周期中每个event中需要做什么事情

    只有 page_load和page_init这些可以autoeventwireup RenderControl只提供override public override void RenderContro ...

  8. Android Service Summary

     In the Androird, service is a none-UI background process that is doing some specific jobs.   6.1 Ex ...

  9. android progressbar 自定义图片匀速旋转

    项目中需要使用圆形进度条进行数据加载的显示,所以需要两个步骤 1:自定义progressbar滚动图片 2:匀速旋转图片 步骤一:自定义progressbar图片 <ProgressBar an ...

随机推荐

  1. 第二篇:基于K-近邻分类算法的约会对象智能匹配系统

    前言 假如你想到某个在线约会网站寻找约会对象,那么你很可能将该约会网站的所有用户归为三类: 1. 不喜欢的 2. 有点魅力的 3. 很有魅力的 你如何决定某个用户属于上述的哪一类呢?想必你会分析用户的 ...

  2. poj 2117 Electricity

    /* Tarjan求割点 */ #include<iostream> #include<cstdio> #include<cstring> #include< ...

  3. poj 1330 LCA (倍增+离线Tarjan)

    /* 先来个倍增 */ #include<iostream> #include<cstring> #include<cstdio> #define maxn 100 ...

  4. left ,right ,cross ,full/left outer join/区别 详解

    --创建测试表wwif OBJECT_ID('qq') is not null drop table qqcreate table qq([序号] varchar(5),[内容1] varchar(1 ...

  5. (转)PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明

    在看帝国cms的connect.php是发现第一句是error_reporting(E_ALL ^ E_NOTICE);以前也没注意过这个语句,知道是设置错误提示的,但不清楚具体怎样设置使用.下面从网 ...

  6. OpenGL ES 3.0 顶点缓冲区VBO使用

    一般情况下数据都是有CPU从RAM取数据 然后传给GPU去处理,相对于GPU速度要慢一些. 使用VBO技术 可以把数据存储到GPU的内存空间中,这样GPU可以直接从GPU的内存中取得数据进行处理 速度 ...

  7. linux术语解析(持续更新)

    1.linux内核有个版本,分别是 longterm: 提供长期支持的内核版本 stable: 稳定版本 Beta 测试版

  8. php 时间戳 总结 今日,昨日,上周,本周,最近三个月,上季,本季,去年,最近七天,今年,最近三十天

    if($time=="今日"){ $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime ...

  9. jQuery图片滑动

    一个非常简单实用的jQuery插件 可以用在页面的顶部广告展示 http://slidesjs.com/ 一个需要注意的问题, 就是在手机等客户端(IOS8以上), 使用此插件时, 经常会触发插件的r ...

  10. 关于一个注册邮箱的demo

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...