启动:    触发 onCreate()   onStart()   onResume()

Home键:   触发 onPause()    onStop()

back键退出: 触发 onPause()   onStop()   onDestroy()

Home键退出再进去: 触发 onRestart()   onStart()  onResume()

启动:

Home键:

再次进入:

退出:

Source:

package com.TreeDream.life;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView; public class MainActivity extends Activity { private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("onCreate"); textView = (TextView)findViewById(R.id.textView1);
textView.setText("onCreate"); } @Override
protected void onStart() {
super.onStart();
System.out.println("onStart"); } @Override
protected void onResume() {
super.onResume();
System.out.println("onResume");
} @Override
protected void onPause() {
super.onPause();
System.out.println("onPause");
} @Override
protected void onStop() {
super.onStop();
System.out.println("onStop");
} @Override
protected void onDestroy() {
super.onDestroy();
System.out.println("onDestroy");
} @Override
protected void onRestart() {
super.onRestart();
System.out.println("onRestart");
textView = (TextView)findViewById(R.id.textView1);
textView.setText("onReStart");
} }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Tree" /> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="40dp"
android:text="" /> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="20dp"
android:text="生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。" /> <ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp"
android:src="@drawable/x" /> </RelativeLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Life</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="Tree">TreeDream Android</string> </resources>

string.xml

Android——Activity生命周期的更多相关文章

  1. [转]: 两分钟彻底让你明白Android Activity生命周期(图文)!

    转自:http://blog.csdn.net/android_tutor/article/details/5772285 大家好,今天给大家详解一下Android中Activity的生命周期,我在前 ...

  2. Android Activity生命周期

    从android api文档摘抄出来的activity生命周期图如下: Activity有如下四种状态 a.活动状态  activity处于屏幕前台,获取到了焦点可以和用户进行交互,同一时刻只有一个a ...

  3. Android Activity生命周期详讲

    管理 Activity 生命周期 通过实现回调方法管理 Activity 的生命周期对开发强大而又灵活的应用至关重要. Activity 的生命周期会直接受到 Activity 与其他 Activit ...

  4. android Activity生命周期(设备旋转、数据恢复等)与启动模式

    1.Activity生命周期     接下来将介绍 Android Activity(四大组件之一) 的生命周期, 包含运行.暂停和停止三种状态,onCreate.onStart.onResume.o ...

  5. Android Activity生命周期以及Fragment生命周期的区别与分析

    Android Fragment生命周期图: Activity生命周期图: 对照图: Fragment生命周期分析: 1. 当一个fragment被创建的时候,它会经历以下状态. onAttach() ...

  6. Android Activity 生命周期详解

    学习android开发这么久对于activity的生命周期还没有仔细思考过,所以,我大致的把这些东西整理一下,希望通过这使自己理解的更透彻点吧! 首先看一下Activity生命周期图和它的的四个阶段 ...

  7. xamarin Android activity生命周期详解

    学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...

  8. Android——Activity生命周期(转)

    Activity生命周期   子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细 ...

  9. Android Activity生命周期的几个问题

      每一个Android开发者都应该知道,android系统有四个重要的基本组件,即Activity(活动).Service(服务).Broadcast Receive(广播接收器)和Content ...

  10. android --Activity生命周期具体解释

    一. 再探Activity生命周期 为了研究activity的生命周期,简单測试代码例如以下. package com.example.testactivity; import android.app ...

随机推荐

  1. UML-2-迭代、进化和敏捷

    1.UP UP:Unified Process,统一过程.RUP:Rational Unified Process,Rational 公司制定的UP,是对UP的精细化. UP的过程: 初始 不是需求, ...

  2. PHP创建自己的Composer包方法

    原文地址:http://www.jb51.net/article/137923.htm

  3. 问题记录——java.lang.IllegalArgumentException: Illegal character in scheme name at index 0

    以下http请求报错是因为,请求的地址前面有个空格.... 2019-01-09 03:30:23,154 ERROR [business.modules.merchantreportresult.s ...

  4. [转]实例化SqlParameter时,如果是字符型,一定要指定size属性

    转自:http://bbs.csdn.net/topics/380155255 以前在实例化SqlParameter时,通常都是用下面的语句,没有设置size属性: new SqlParameter( ...

  5. Linux下远程连接工具SSHSecureShellClient的使用

    实际开发中,Linux 服务器都在其他的地方,我们要通过远程的方式去连接 Linux 并操作它,Linux 远程的操作工具有很多,企业中常用的有 Puttty.secureCRT.SSH Secure ...

  6. [Activator-HelloAkka] Define our Actors

    The Actor is the unit of execution in Akka. Actors are object-oriented in the sense that they encaps ...

  7. nyoj 206——矩形的个数——————【dp或公式】

    矩形的个数 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1*2的矩形,2个2*2的矩形,2个3 ...

  8. dpkg: error: dpkg status database is locked by another process 解决方法

    使用dpkg -i/apt命令安装,报错: ------------------------------------------------------------- dpkg: error: dpk ...

  9. nginx配置文件分开配置

    在Linux中不同的用户都可能用到Nginx,如果不同的用户无法达成一个对nginx.conf编写标准,势必会导致nginx.conf里的内容变的相当混乱,极难维护.所以这里建议新建一个文件夹,这个文 ...

  10. Jquery系列:checkbox 获取值、选中、设置值、事件监听等操作

    <div id="divId" class="divTable"> <div class="tableBody"> ...