[4.18]Android生命周期介绍
16lz
2021-01-23
抄着敲着
#1 Activity:
Activity是一个交互界面,可以布满整个窗口,或者悬浮于其他窗口上
一个程序由多个Activity组成,Manifest中指明了主Activity
<activity <span style="white-space:pre"></span>android:label="@string/app_name"<span style="white-space:pre"></span>android:name=".MainActivity" > <intent-filter > <span style="white-space:pre"></span><action android:name="android.intent.action.MAIN" /> <span style="white-space:pre"></span><category android:name="android.intent.category.LAUNCHER" /> </intent-filter></activity>
Activity是一个互相调用关系,以栈的形式存取
#2 生命周期
voidonCreate(Bundle savedInstanceState)
voidonStart()
voidonRestart()
voidonResume()
voidonPause()
voidonStop()
voidonDestroy()
开始Activity:onCreate、onStart和onResume方法。
Activity失去焦点:onPause、onStop
Activity重新获得焦点:onRestart、onStart和onResume
关闭Activity:onPause、onStop和onDestory
#3 测试代码
package com.android.mylife;import android.app.Activity;import android.os.Bundle;import android.util.Log;public class Main extends Activity {/** Called when the activity is first created. */private final String TAG = "Main";@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);Log.i(TAG, "onCreate Method is executed");}@Overrideprotected void onStart() {// TODO Auto-generated method stubsuper.onStart();Log.i(TAG, "onStart Method is executed");}@Overrideprotected void onRestart() {// TODO Auto-generated method stubsuper.onRestart();Log.i(TAG, "onRestart Method is executed");}@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();Log.i(TAG, "onResume Method is executed");}@Overrideprotected void onStop() {// TODO Auto-generated method stubsuper.onStop();Log.i(TAG, "onStop Method is executed");}@Overrideprotected void onPause() {// TODO Auto-generated method stubsuper.onPause();Log.i(TAG, "onPause Method is executed");}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();Log.i(TAG, "onDestroy Method is executed");}}
更多相关文章
- Android 结合WindowManager和WindowManager.LayoutParams显示窗
- android View根据自己获取焦点的情况执行语句
- android editview与popwindow焦点冲突
- android: 不需要焦点的TextView跑马灯 MarqueeTextView
- Android Studio实现Activity生命周期的7个方法Log打印日志信息
- Android 应用软件开发(八)窗口布局
- Android之Servic的生命周期和调用方法
- APP横竖屏不切换,不重走生命周期
- Android开发入门之学习笔记(四):程序窗口的布局(二)