1. 在xml 设计页面添加标签

xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.administrator.app_style.MainActivity"
android:orientation="vertical"> <Button
android:id="@+id/b1"
android:text="click select!"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/b2"
android:text="click Dx!"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> LinearLayout>

  2

 
/**
* Created by Administrator on 2017/1/3.
* 四大组件都需要注册-》跳转
*/ public class One extends AppCompatActivity { // 顺序
// 正常
//
// On create -> 创建 Activity不可见
// On start -> 推出去 Activity可见
// On resume-> 用于暂停的回调Activity
// On pause -> 暂停 Activity
// On stop -> OnDestory 销毁Activity结束
//↓ ↑ ← →
// Log →.d debug .e exception .i info @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timcopy);
Log.e("s","onCreate ->");
} @Override
protected void onStart() {
super.onStart();
Log.e("s","onStart ->");
} @Override
protected void onResume() {
super.onResume();
Log.e("s","onResume ->");
} @Override
protected void onPause() {
super.onPause();
Log.e("s","onPause ->");
} @Override
protected void onStop() {
super.onStop();
Log.e("s","onStop() ->");
} @Override
protected void onDestroy() {
super.onDestroy();
Log.e("s","onDestroy()");
}
<!DOCTYPE html><html lang='zh-cn'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='content - type' content='text/html; charset=UTF-8'>
<metaname='viewport' content='width=device-width,initial-scale=1.0'/>
<title>安卓——Activity生命周期</title></head><body><div><br></div><div><pre style="font-size: 10.5pt; font-family: 宋体;"><pre style="font-family: 宋体; font-size: 10.5pt;"><pre style="font-family: 宋体; font-size: 10.5pt;"><ol><li>在xml 设计页面添加标签</li></ol> <?<span style="font-size: 10.5pt; color: rgb(0, 0, 255); font-weight: bold;">xml version=</span><span style="font-size: 10.5pt; color: rgb(0, 128, 0); font-weight: bold;">"1.0" </span><span style="font-size: 10.5pt; color: rgb(0, 0, 255); font-weight: bold;">encoding=</span><span style="font-size: 10.5pt; color: rgb(0, 128, 0); font-weight: bold;">"utf-8"</span><span style="font-size: 10.5pt; font-style: italic;">?></span><pre style="background-color: rgb(255, 255, 255); font-family: 宋体; font-size: 10.5pt;"><<span style="color:#000080;font-weight:bold;">LinearLayout </span><span style="color:#0000ff;font-weight:bold;">xmlns:</span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">=</span><span style="color:#008000;font-weight:bold;">"http://schemas.android.com/apk/res/android"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#0000ff;font-weight:bold;">xmlns:</span><span style="color:#660e7a;font-weight:bold;">app</span><span style="color:#0000ff;font-weight:bold;">=</span><span style="color:#008000;font-weight:bold;">"http://schemas.android.com/apk/res-auto"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#0000ff;font-weight:bold;">xmlns:</span><span style="color:#660e7a;font-weight:bold;">tools</span><span style="color:#0000ff;font-weight:bold;">=</span><span style="color:#008000;font-weight:bold;">"http://schemas.android.com/tools"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:layout_width=</span><span style="color:#008000;font-weight:bold;">"match_parent"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:layout_height=</span><span style="color:#008000;font-weight:bold;">"match_parent"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">tools</span><span style="color:#0000ff;font-weight:bold;">:context=</span><span style="color:#008000;font-weight:bold;">"com.example.administrator.app_style.MainActivity"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:orientation=</span><span style="color:#008000;font-weight:bold;">"vertical"</span>><br><br> <<span style="color:#000080;font-weight:bold;">Button<br></span><span style="color:#000080;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:id=</span><span style="color:#008000;font-weight:bold;">"@+id/b1"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:text=</span><span style="color:#008000;font-weight:bold;">"click select!"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:layout_width=</span><span style="color:#008000;font-weight:bold;">"match_parent"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:layout_height=</span><span style="color:#008000;font-weight:bold;">"wrap_content" </span>/><br> <<span style="color:#000080;font-weight:bold;">Button<br></span><span style="color:#000080;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:id=</span><span style="color:#008000;font-weight:bold;">"@+id/b2"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:text=</span><span style="color:#008000;font-weight:bold;">"click Dx!"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:layout_width=</span><span style="color:#008000;font-weight:bold;">"match_parent"<br></span><span style="color:#008000;font-weight:bold;"> </span><span style="color:#660e7a;font-weight:bold;">android</span><span style="color:#0000ff;font-weight:bold;">:layout_height=</span><span style="color:#008000;font-weight:bold;">"wrap_content" </span>/><br><br></<span style="color:#000080;font-weight:bold;">LinearLayout</span>><br></pre><hr style="font-size: 10.5pt;"></pre><pre style="font-family: 宋体; font-size: 10.5pt;"> 2</pre><pre style="font-family: 宋体; font-size: 10.5pt;"><pre style="background-color: rgb(255, 255, 255); font-family: 宋体; font-size: 10.5pt;"><br><span style="color:#808080;font-style:italic;">/**<br></span><span style="color:#808080;font-style:italic;"> * Created by Administrator on 2017/1/3.<br></span><span style="color:#808080;font-style:italic;"> * 四大组件都需要注册-》跳转<br></span><span style="color:#808080;font-style:italic;"> */<br></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#000080;font-weight:bold;">public class </span>One <span style="color:#000080;font-weight:bold;">extends </span>AppCompatActivity {<br><br><span style="color:#808080;font-style:italic;">// 顺序<br></span><span style="color:#808080;font-style:italic;">// 正常<br></span><span style="color:#808080;font-style:italic;">//<br></span><span style="color:#808080;font-style:italic;">// On create -> 创建 Activity不可见<br></span><span style="color:#808080;font-style:italic;">// On start -> 推出去 Activity可见<br></span><span style="color:#808080;font-style:italic;">// On resume-> 用于暂停的回调Activity<br></span><span style="color:#808080;font-style:italic;">// On pause -> 暂停 Activity<br></span><span style="color:#808080;font-style:italic;">// On stop -> OnDestory 销毁Activity结束<br></span><span style="color:#808080;font-style:italic;">//↓ ↑ ← →<br></span><span style="color:#808080;font-style:italic;">// Log →.d debug .e exception .i info<br></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#808080;font-style:italic;"><br></span><span style="color:#808080;font-style:italic;"> </span><span style="color:#808000;">@Override<br></span><span style="color:#808000;"> </span><span style="color:#000080;font-weight:bold;">protected void </span>onCreate(@Nullable Bundle savedInstanceState) {<br> <span style="color:#000080;font-weight:bold;">super</span>.onCreate(savedInstanceState);<br> setContentView(R.layout.<span style="color:#660e7a;font-weight:bold;font-style:italic;">timcopy</span>);<br> Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;font-weight:bold;">"s"</span>,<span style="color:#008000;font-weight:bold;">"onCreate ->"</span>);<br> }<br><br> <span style="color:#808000;">@Override<br></span><span style="color:#808000;"> </span><span style="color:#000080;font-weight:bold;">protected void </span>onStart() {<br> <span style="color:#000080;font-weight:bold;">super</span>.onStart();<br> Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;font-weight:bold;">"s"</span>,<span style="color:#008000;font-weight:bold;">"onStart ->"</span>);<br> }<br><br> <span style="color:#808000;">@Override<br></span><span style="color:#808000;"> </span><span style="color:#000080;font-weight:bold;">protected void </span>onResume() {<br> <span style="color:#000080;font-weight:bold;">super</span>.onResume();<br> Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;font-weight:bold;">"s"</span>,<span style="color:#008000;font-weight:bold;">"onResume ->"</span>);<br> }<br><br> <span style="color:#808000;">@Override<br></span><span style="color:#808000;"> </span><span style="color:#000080;font-weight:bold;">protected void </span>onPause() {<br> <span style="color:#000080;font-weight:bold;">super</span>.onPause();<br> Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;font-weight:bold;">"s"</span>,<span style="color:#008000;font-weight:bold;">"onPause ->"</span>);<br> }<br><br> <span style="color:#808000;">@Override<br></span><span style="color:#808000;"> </span><span style="color:#000080;font-weight:bold;">protected void </span>onStop() {<br> <span style="color:#000080;font-weight:bold;">super</span>.onStop();<br> Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;font-weight:bold;">"s"</span>,<span style="color:#008000;font-weight:bold;">"onStop() ->"</span>);<br> }<br><br> <span style="color:#808000;">@Override<br></span><span style="color:#808000;"> </span><span style="color:#000080;font-weight:bold;">protected void </span>onDestroy() {<br> <span style="color:#000080;font-weight:bold;">super</span>.onDestroy();<br> Log.<span style="font-style:italic;">e</span>(<span style="color:#008000;font-weight:bold;">"s"</span>,<span style="color:#008000;font-weight:bold;">"onDestroy()"</span>);<br> }</pre></pre><pre style="font-family: 宋体; font-size: 10.5pt;"><hr><pre style="font-family: 宋体; font-size: 10.5pt;"> </pre></pre></pre></pre></div></body></html>

 


 

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

  1. 安卓activity生命周期

    相信不少朋友也已经看过这个流程图了,也基本了解了Activity生命周期的几个过程,我们就来说一说这几个过程. 1.启动Activity:系统会先调用onCreate方法,然后调用onStart方法, ...

  2. 安卓 Activity 生命周期

    创建到销毁的生命周期: onCreate()->onStart()->onResume()->onPause->onStop->onDestroy 启动到前台在到后台的生 ...

  3. 安卓——Activity生命周期、

    在xml 设计页面添加标签 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln ...

  4. 安卓Activity生命周期(转)

    http://www.oschina.net/question/54100_27841 启动:onCreate()->onStart()->onResume 当从Activity界面直接按 ...

  5. 零基础Android学习笔记-02 安卓程序生命周期

    一个安卓程序生命周期会经历7中状态,并不一定是每次都全部经历.Create,Start,ReStart,Pause,Resume,Stop,Destory. 重载方法,用helloWorld程序去体验 ...

  6. [JIT_APP]Activity生命周期相关的7个方法

    先发一张安卓官方文档里面的Activity生命周期图解 下面在对这7个生命周期内相关的方法做一些简单的介绍 OnCreate() 当Activity被创建的时候,会自动运行该方法.该方法做一些初始化动 ...

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

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

  8. Activity生命周期(深入理解)

    今天看到一篇大神总结Activity的文章,内容甚为详细,特此转载http://www.cnblogs.com/lwbqqyumidi/p/3769113.html Android官方文档和其他不少资 ...

  9. Android Activity生命周期

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

随机推荐

  1. kubernetes 实战6_命令_Share Process Namespace between Containers in a Pod&Translate a Docker Compose File to Kubernetes Resources

    Share Process Namespace between Containers in a Pod how to configure process namespace sharing for a ...

  2. sql server数据库自动备份

    SqlServer 数据库自动备份的两种解决方案 SQL Server中的角色(服务器级别和数据库级别角色) SqlServer服务器角色和数据库角色相关操作

  3. maven web项目配置log4j,及log4j参数设置

    本文为博主原创,转载须注明转载地址: 1.在maven项目中引入相关的依赖: 需要依赖的jar为: <!-- 配置日志 --> <dependency> <groupId ...

  4. Mac环境下扩容 .vmdk 镜像容量

    参考: Resizing a VirtualBox Disk Image (.vmdk) on a Mac Mac环境下扩容 .vmdk 镜像容量 在安装虚拟机时,原有的vmdk镜像容量只有20G,在 ...

  5. 《机器学习实战》之k-近邻算法(改进约会网站的配对效果)

    示例背景: 我的朋友海伦一直使用在线约会网站寻找合适自己的约会对象.尽管约会网站会推荐不同的人选,但她并不是喜欢每一个人.经过一番总结,她发现曾交往过三种类型的人: (1)不喜欢的人: (2)魅力一般 ...

  6. 使用explain来分析SQL语句实现优化SQL语句

    用法:explain sql 作用:用于分析sql语句 mysql> explain select * from quser_1 where loginemail = "quctest ...

  7. chrome浏览器的SwitchyOmega插件使用方法

    对于有某些特殊需求的人来讲,应该对这个插件不陌生,但是很多人不了解这插件的工作原理,百度的老教程又很烂,在刚开始用的时候我也不知道怎么办,去百度搜出来的教程基本都是让下载个规则文件让你去导入,但一般这 ...

  8. .NET扩展方法 封装公用方法

    定义方法的时候  第一个参数前面加上this   表示这个方法可以被IQueryable类型的对象.出来  调用的时候 只用传第二个参数  第一个参数不用传 第一个参数就是.出当前方法的参数 定义扩展 ...

  9. 大话WebRTC的前世今生

    音视频的历史 音视频可以说是人类与生俱来的需求,人一出生就要用耳朵听,用眼睛看.中国的古代神话中为此还专门设置了两位神仙(千里眼和顺风耳),他们可以听到或看到千里之外的声音或景像. 为了解决听的远和看 ...

  10. python第二章(2)列表

    names=["zhangyang","guyun","xiangpeng","leiming","xulia ...