Android Studio之 Activity 的生命周期

今日长缨在手,何时缚住苍龙。这篇文章主要讲述Android Studio之 Activity 的生命周期相关的知识,希望能为你提供帮助。
android的Activity的生命周期

Android Studio之 Activity 的生命周期

文章图片

 
 
翻转屏幕,会重新加载Activity
 
package com.example.activitylivecycle; import android.os.Bundle; import android.util.Log; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity {//定义 TAG 方便自己容易查找日志 //翻转屏幕,Activity 会重新创建加载 String TAG = "myTag"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG,"onCreate: "); }@Override protected void onStart() { super.onStart(); Log.d(TAG,"onStart: "); }@Override protected void onResume() { super.onResume(); Log.d(TAG,"onResume: "); }@Override protected void onPause() { super.onPause(); Log.d(TAG,"onPause: "); }@Override protected void onStop() { super.onStop(); Log.d(TAG,"onStop: "); }@Override protected void onRestart() { super.onRestart(); Log.d(TAG,"onRestart: "); }@Override protected void onDestroy() { super.onDestroy(); Log.d(TAG,"onDestroy: "); }}


 
打开app后产生的事件 2019-11-01 19:28:59.070 3334-3334/com.example.activitylivecycle D/myTag: onCreate: 2019-11-01 19:28:59.071 3334-3334/com.example.activitylivecycle D/myTag: onStart: 2019-11-01 19:28:59.072 3334-3334/com.example.activitylivecycle D/myTag: onResume: 屏幕翻转后执行顺序 2019-11-01 19:29:10.748 3334-3334/com.example.activitylivecycle D/myTag: onPause: 2019-11-01 19:29:10.772 3334-3334/com.example.activitylivecycle D/myTag: onStop: 2019-11-01 19:29:10.772 3334-3334/com.example.activitylivecycle D/myTag: onDestroy: 2019-11-01 19:29:10.792 3334-3334/com.example.activitylivecycle D/myTag: onCreate: 2019-11-01 19:29:10.807 3334-3334/com.example.activitylivecycle D/myTag: onStart: 2019-11-01 19:29:10.811 3334-3334/com.example.activitylivecycle D/myTag: onResume:


【Android Studio之 Activity 的生命周期】 

    推荐阅读