Android——Activity生命周期
启动: 触发 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生命周期的更多相关文章
- [转]: 两分钟彻底让你明白Android Activity生命周期(图文)!
转自:http://blog.csdn.net/android_tutor/article/details/5772285 大家好,今天给大家详解一下Android中Activity的生命周期,我在前 ...
- Android Activity生命周期
从android api文档摘抄出来的activity生命周期图如下: Activity有如下四种状态 a.活动状态 activity处于屏幕前台,获取到了焦点可以和用户进行交互,同一时刻只有一个a ...
- Android Activity生命周期详讲
管理 Activity 生命周期 通过实现回调方法管理 Activity 的生命周期对开发强大而又灵活的应用至关重要. Activity 的生命周期会直接受到 Activity 与其他 Activit ...
- android Activity生命周期(设备旋转、数据恢复等)与启动模式
1.Activity生命周期 接下来将介绍 Android Activity(四大组件之一) 的生命周期, 包含运行.暂停和停止三种状态,onCreate.onStart.onResume.o ...
- Android Activity生命周期以及Fragment生命周期的区别与分析
Android Fragment生命周期图: Activity生命周期图: 对照图: Fragment生命周期分析: 1. 当一个fragment被创建的时候,它会经历以下状态. onAttach() ...
- Android Activity 生命周期详解
学习android开发这么久对于activity的生命周期还没有仔细思考过,所以,我大致的把这些东西整理一下,希望通过这使自己理解的更透彻点吧! 首先看一下Activity生命周期图和它的的四个阶段 ...
- xamarin Android activity生命周期详解
学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...
- Android——Activity生命周期(转)
Activity生命周期 子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细 ...
- Android Activity生命周期的几个问题
每一个Android开发者都应该知道,android系统有四个重要的基本组件,即Activity(活动).Service(服务).Broadcast Receive(广播接收器)和Content ...
- android --Activity生命周期具体解释
一. 再探Activity生命周期 为了研究activity的生命周期,简单測试代码例如以下. package com.example.testactivity; import android.app ...
随机推荐
- TCP/IP协议分为哪四层,具体作用是什么。
TCP/IP通讯协议采用了4层的层级结构,每一层都呼叫它的下一层所提供的网络来完成自己的需求.这4层分别为: 应用层:应用程序间沟通的层,如简单电子邮件传输(SMTP).文件传输协议(FTP).网络远 ...
- oracle 笔记---(三)__体系架构
查看控制文件位置 SQL> show parameter control_files; NAME TYPE VALUE ------------------------------------ ...
- jdk监控tomcat
一, tomcat配置文件 在tomcat的配置文件中添加被监控的项 #在tomcat配置文件中开启监控功能 vim /application/tomcat/bin/catalina.sh +97 C ...
- NFS 优化及详解
一, 启动过程: 所以启动的时候一定一定要先启用——————rpcbind———————————————— 启动 rpcbind ------>/etc/init.d/rpcbind rest ...
- 常用css搜集
div居中显示 position: fixed; top: 130px; left:0px;right:0px;margin-left:auto;margin-right:auto;
- mongodb常用语句(集合操作)
mongodb常用语句(集合操作) 查看集合帮助 db.songs.help(); 查看集合总数据量 db.songs.count(); 查看表空间大小 db.songs.dataSize(); 查看 ...
- nyoj 61——传纸条(一)——————【双线dp】
传纸条(一) 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行 ...
- 【转】常用的邮箱服务器(SMTP、POP3)地址、端口
gmail(google.com)POP3服务器地址:pop.gmail.com(SSL启用 端口:995)SMTP服务器地址:smtp.gmail.com(SSL启用 端口:587) 21cn.co ...
- [转]ASP.NET Core Exception Filters and Resource Filters
本文转自:https://damienbod.com/2015/09/30/asp-net-5-exception-filters-and-resource-filters/ This article ...
- django细节
1.处理请求 1.1 /add/?a=4&b=5 这样GET方法进行[获取参数] from django.shortcuts import render from django.http i ...