1.观察 Activity 完整的生命周期。 2.观察 Activity 进入后台,从后台返回时的生命周期
Android 生命周期是从程序启动到程序终止的过程。通过本次实验深入理解 Android 系统管理生命周期的必要性,并以 Activity 为例说明 Android 系统是如何管理程序组件的生命周期。
通过实验来观察activity界面的生命周期
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content&#