枕上从妨一夜睡,灯前读尽十年诗。这篇文章主要讲述安卓-生命周期相关的知识,希望能为你提供帮助。
实验目的:
生成运行第一个android程序,熟悉了解Android手机开发平台的基本构成和使用方法,熟悉Android应用程序项目的基本文件目录结构,了解开发环境提供的各种工具的基本用法。
在Activity中重载下9种事件函数,在调用不同函数时使用LogCat在Eclipse的控制台中输出调用日志。掌握Activity在启动、停止和销毁等不同阶段,9种重载函数的调用顺序,并掌握Android调试工具LogCat的使用方法

文章图片

文章图片

文章图片
1 package com.example.administrator.myapplication; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.util.Log; 6 7 public class MainActivity extends AppCompatActivity { 8 9private static String TAG = "LIFECYCLE"; 10 11@Override 12protected void onCreate(Bundle savedInstanceState) { 13super.onCreate(savedInstanceState); 14setContentView(R.layout.activity_main); 15Log.i(TAG, "onCreate"); 16} 17 18@Override 19protected void onStart() { 20super.onStart(); 21Log.i(TAG, "onStart"); 22} 23 24@Override 25protected void onResume() { 26super.onResume(); 27Log.i(TAG, "onResume"); 28} 29 30@Override 31protected void onRestart() { 32super.onRestart(); 33Log.i(TAG, "onRestart"); 34} 35 36@Override 37protected void onPause() { 38super.onPause(); 39Log.i(TAG, "onPause"); 40} 41 42@Override 43protected void onStop() { 44super.onStop(); 45Log.i(TAG, "onStop"); 46} 47 48@Override 49protected void onDestroy() { 50super.onDestroy(); 51Log.i(TAG, "onDestroy"); 52} 53 54@Override 55protected void onSaveInstanceState(Bundle outState) { 56super.onSaveInstanceState(outState); 57Log.i(TAG, "onSaveInstanceState"); 58} 59 60@Override 61protected void onRestoreInstanceState(Bundle savedInstanceState) { 62super.onRestoreInstanceState(savedInstanceState); 63Log.i(TAG, "onRestoreInstanceState"); 64} 65 66 }
MainActivity.java

文章图片

文章图片
1 < ?xml version="1.0" encoding="utf-8"?> 2 < android.support.constraint.ConstraintLayout 3xmlns:android="http://schemas.android.com/apk/res/android" 4xmlns:tools="http://schemas.android.com/tools" 5xmlns:app="http://schemas.android.com/apk/res-auto" 6android:layout_width="match_parent" 7android:layout_height="match_parent" 8tools:context="com.example.administrator.myapplication.MainActivity"> 9 10< TextView 11android:layout_width="wrap_content" 12android:layout_height="wrap_content" 13android:text="Hello World!" 14app:layout_constraintBottom_toBottomOf="parent" 15app:layout_constraintLeft_toLeftOf="parent" 16app:layout_constraintRight_toRightOf="parent" 17app:layout_constraintTop_toTopOf="parent" /> 18 19 < /android.support.constraint.ConstraintLayout>
activity_main.xml

文章图片

文章图片
1 < ?xml version="1.0" encoding="utf-8"?> 2 < manifest xmlns:android="http://schemas.android.com/apk/res/android" 3package="com.example.administrator.myapplication" > 4 5< application 6android:allowBackup="true" 7android:icon="@mipmap/ic_launcher" 8android:label="@string/app_name" 9android:roundIcon="@mipmap/ic_launcher_round" 10android:supportsRtl="true" 11android:theme="@style/AppTheme" > 12< activity android:name=".MainActivity" > 13< intent-filter> 14< action android:name="android.intent.action.MAIN" /> 15 16< category android:name="android.intent.category.LAUNCHER" /> 17< /intent-filter> 18< /activity> 19< /application> 20 21 < /manifest>
AndroidManifest.xml【安卓-生命周期】
推荐阅读
- DefaultNamespaceHandlerResolver中handlerMappings如何初始化
- EOSDapp 上的×××游戏还有戏吗?
- Android wpa_supplicant 四次握手 流程分析
- 8分钟学会使用AutoMapper
- Android常用开源库的使用——————————————LitePal的使用方法
- 一对一直播系统app开发核心功能点简析
- 探探app下载|探探app下载
- 从golang-gin-realworld-example-app项目学写httpapi
- 安卓之Android.mk编写