• 安卓——Activity生命周期


    
     
    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>
    
    
     

    
     
  • 相关阅读:
    Linux_进程之间的通信
    Linux_控制作业(管理)
    Linux_进程管理相关命令
    Linux_进程管理的基本概述
    文本编辑_Vim&Vi
    Linux_权限管理理论概述
    Linux_用户和组管理
    Linux_ACL文件访问控制列表
    72. VUE axios 配置信息相关
    71. VUE axios 发送并发请求(多个)
  • 原文地址:https://www.cnblogs.com/embaobao/p/10720866.html
Copyright © 2020-2023  润新知