Callback Description
onCreate() This is the first callback and called when the activity is first created.
onStart() This callback is called when the activity becomes visible to the user.
onResume() This is called when the user starts interacting with the application.
onPause() The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed.
onStop() This callback is called when the activity is no longer visible.
onDestroy() This callback is called before the activity is destroyed by the system.
onRestart() This callback is called when the activity restarts after stopping it.

关键代码如下:

public class MainActivity extends Activity {
private String msg="Android: ";
/**
* Called when the activity is first created.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}

/**
* Called when the activity is about to become visible.
*/
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.d(msg, "The onStart() event");
}

/**
* Called when the activity has become visible.
*/
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.d(msg, "The onResume() event");
}

/**
* Called when another activity is taking focus.
*/
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d(msg, "The onPause() event");
}

/**
* Called when the activity is no longer visible.
*/
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.d(msg, "The onStop() event");
}

/**
* Called just before the activity is destroyed.
*/
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}

运行截图:

当Activity第一次打开时:

当启动另一个Activity时:

当关闭当前的Activity,返回到先前的Activity时:

当销毁当前Activity时:

初识Activity的更多相关文章

  1. 二、Android学习第二天——初识Activity(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 一. Android学习第二天——初识Activity 昨天程序搭建成功以 ...

  2. android开发------初识Activity

    之前我们简单说过,Activity实际上是一个窗体,用来存放我们的程序外观. 我们先来创建一个空的Activity,不加载任何layout.要做的是,定义自己的类,继承android的Activity ...

  3. 1、初识Activity

    Activity是Android的基本组成部分,是人机交互程序入口:一个Android项目由多个Activity组成,所有的显示组件必须放在Activity上才能进行显示. (1)Android项目工 ...

  4. Android学习笔记二之初始Activity

    初识Activity,跟着教程学习敲了一遍这一章的内容,下面根据目录结构总结知识点: 一.活动是什么 上篇博文中我们提到了Android四大组件,其中有一个Activity,我们将之称为活动.活动是最 ...

  5. 浅谈Android之Activity生命周期

     Activity作为四大组件之一,出现的频率相当高,基本上我们在android的各个地方都能看见它的踪影,因此深入了解Activity,对于开发高质量应用程序是很有帮助的.今天我们就来详细地聊聊Ac ...

  6. android开发之路01

    一.android系统被分为4个层次:1.最下层的是linux核心,包括多个驱动程序,提供了操作系统应该具备的核心功能:2.在linux核心之上,包括两个部分,一部分是Android Runtime( ...

  7. Android入门:MVC模式(中)

    MVC 模式的最基本概念是分层设计,把我们的代码基于 View(视图).Model(模型).Controller(控制器)进行分类封装,这样做的目的是为了清晰结构,使代码更易维护和扩展. 在上一篇文章 ...

  8. 0基础学安卓--初识安卓Activity

    知识储备:windows+ Android Studio 等环境安装. 安卓中Activity代表页的意思,也就是☞我们手机上当前的整个界面显示,点击按钮等操作可以跳转到另外一个Activity中. ...

  9. Android四大组件初识之Activity

    一.Activity的生命周期 Activity生命周期是一系列方法调用.熟悉各个方法调用时间,我们在创建activity就能根据具体实现选择合适的方法覆盖. 1.  覆盖Activity的生命周期方 ...

随机推荐

  1. [BZOJ 3172] [Tjoi2013] 单词 【AC自动机】

    题目链接:BZOJ - 3172 题目分析: 题目要求求出每个单词出现的次数,如果把每个单词都在AC自动机里直接跑一遍,复杂度会很高. 这里使用AC自动机的“副产品”——Fail树,Fail树的一个性 ...

  2. Compare Version Number

    package cn.edu.xidian.sselab.string; /** *  * @author zhiyong wang * title: Compare Version Numbers  ...

  3. YII 主题

    heming是一个在Web应用程序里定制网页外观的系统方式.通过采用一个新的主题,网页应用程序的整体外观可以立即和戏剧性的改变. 在Yii,每个主题由一个目录代表,包含view文件,layout文件和 ...

  4. 分页SQL取下一页

    20条记录一页,扫描第2页就需要访问40条记录. SQL> select * from ( select * from ( select /*+ index_desc(a idx_page_3) ...

  5. A Round Peg in a Ground Hole(判断是否是凸包,点是否在凸包内,圆与多边形的关系)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4628   Accepted: 1434 Description The D ...

  6. 「Poetize7」足球比赛

    描述 Description SJZEZ和TSYZ正在进行一轮足球联谊赛,根据规则,这轮比赛有两场,一场在SJZEZ的主场进行,一场在TSYZ的主场进行.胜负判断标准如下:1.在两场比赛中进球总数较多 ...

  7. First Bad Version——LeetCode

    You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...

  8. 高效算法——C 分饼

    My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...

  9. linux内网机器访问外网代理设置squid

    公司一般出于安全考虑, 在同一局域网中只有一台机器可以访问外网,运维进行了整体的限制, 但是在后面的工作中,需要在机器上安装一些软件,及命令,所以其他的机器需要访问外网来简化工作, 但又不能打乱原有运 ...

  10. 借助github搭建自己的博客

    创建GitHub技术博客全攻略 通过GitHub Pages建立个人站点(详细步骤) 备注: 我搭建成功了,但是访问时只能使用"http://username.github.io/usern ...