Activity LifeCycle (安卓应用的运行机制)

时间:2021-10-10 17:56:48

Activity LifeCycle (安卓应用的运行机制)

 

 

测试回调代码

Activity LifeCycle (安卓应用的运行机制)Activity LifeCycle (安卓应用的运行机制)
package com.example.hello;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    String TAG="myTag";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG,  "on Create:");
    }
    @Override
    protected void onStart(){
        super.onStart();
        Log.d(TAG,"on Start:");
    }
    @Override
    protected void onResume(){
        super.onResume();
        Log.d(TAG,"on Resume:");
    }

    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG,"on Pause:");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG,"on Stop:");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d(TAG,"on Restart:");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG,"on Destroy:");
    }
}
MainActivity

 

测试结果

Activity LifeCycle (安卓应用的运行机制)