package com.example.yanlei.yl2;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView; public class MainActivity extends AppCompatActivity {
public static final String TAG = "生命周期:";
String Str = "";
TextView pTextView = null; @Override
public void onCreate(Bundle savedInstanceState) {
//当创建此Activity的时候回调
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(TAG, "onCreate");
try {
Str = Str + "创建:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
} } @Override
protected void onDestroy() {
//当销毁此Activity的时候回调
super.onDestroy();
Log.e(TAG, "onDestroy"); try {
Str = Str + "摧毁:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
} @Override
protected void onPause() {
//当暂停此Activity的时候回调
super.onPause();
Log.e(TAG, "onPause");
try {
Str = Str + "暂停:\n";
pTextView.setText(Str);
} catch (Exception e) {
// Log.e(TAG, "error : "+e.getMessage(), e);
}
} @Override
protected void onRestart() {
//当重新开始此Activity的时候回调
super.onRestart();
Log.e(TAG, "onRestart");
try {
Str = Str + "重新启动:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
} @Override
protected void onResume() {
//当显示展示此Activity的界面的时候回调
super.onResume();
Log.e(TAG, "onResume");
try {
Str = Str + "继续:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
} @Override
protected void onStart() {
//当使用此Activity可以接受用户操作的时候回调
super.onStart();
Log.e(TAG, "onStart");
try {
Str = Str + "开始:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
} @Override
protected void onStop() {
//当停止此Activity的时候回调
super.onStop();
Log.e(TAG, "onStop");
try {
Str = Str + "停止:\n";
pTextView.setText(Str);
} catch (Exception e) {
//Log.e(TAG, "error : "+e.getMessage(), e);
}
} }

日志如下:

onCreate
onStart
onResume

onPause
onStop
onDestroy

android Activity生命周期的例子的更多相关文章

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

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

  2. Android Activity 生命周期详解

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

  3. Android Activity生命周期

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

  4. Android Activity生命周期详讲

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

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

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

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

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

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

随机推荐

  1. Linux运维发展与学习路线图

    记录一下Linux所要懂的知识体系,方便未来学习的时候自我验证. Linux运维课程体系大纲: Linux入门 了解Linux基础,知道什么是Linux,会安装Linux,使用相关基础命令,如:cd, ...

  2. Git学习——从远程库克隆

    克隆一个本地库 首先准备好一个远程库.再用命令克隆一个本地库. git clone git@github.com:<github账户>/<远程库名>.git 克隆一个仓库,首先 ...

  3. mysql 慢查询日志 mysqldumpslow 工具

    文章来源:https://www.cnblogs.com/hello-tl/p/9229676.html 1.使用Mysql慢查询日志配置 查看慢查询日志是否开启 OFF关闭 ON开启 show va ...

  4. Google 超分辨率技术 RAISR

    每天都有数以百万计的图片在网络上被分享.储存,用户借此探索世界,研究感兴趣的话题,或者与朋友家人分享假期照片.问题是,大量的图片要嘛被照相设备的像素所限制,要嘛在手机.平板或网络限制下被人为压缩,降低 ...

  5. linux 环境下bash脚本中找不到命令

    mr.sh: line 1: HADOOP_CMD: command not found mr.sh: line 4: INPUT_FILE_PATH: command not found mr.sh ...

  6. python中判断字符串是否为中文

    判断字符串是否在中文编码范围内 for c in s:        if not ('\u4e00' <= c <= '\u9fa5'):            return False ...

  7. 编辑器sublime(转)摘自网络

    一.下载和安装 Sublime Text2是一款开源的软件,不需要注册即可使用(虽然没有注册会有弹窗,但是基本不影响使用). 下载地址:http://www.sublimetext.com/,请自行根 ...

  8. webforms字典参数处理

    当webforms参数中的value是一个字典时,加上‘’即可正常传参.

  9. iOS 绕过https证书验证 请求数据

    HTTPS和HTTP: 1.https协议需要到ca申请证书,一般免费证书很少,需要交费. 2.http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议. 3.http ...

  10. python刷toj

    1452 import sys a , b , c = map(int,sys.stdin.readline().split()) print ((a+b+c),(a*b*c), '%.2f' %(( ...