MainActivity .java
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import java.util.function.LongToDoubleFunction;
public class MainActivity extends Activity {
//日志标记
private String TAG = this.getClass().getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG,"---------------onCreate------创建------");
setContentView(R.layout.main);
}
@Override
protected void onStart() {
super.onStart();
Log.i(TAG,"---------------onStart---- 开始--------");
}
@Override
protected void onResume() {
super.onResume();
Log.i(TAG,"---------------onResume---- 运行--------");
}
@Override
protected void onPause() {
super.onPause();
Log.i(TAG,"---------------onPause---- 暂停--------");
}
@Override
protected void onStop() {
super.onStop();
Log.i(TAG,"---------------onStop---- 停止--------");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG,"---------------onDestroy---- 销毁--------");
}
@Override
protected void onRestart() {
super.onRestart();
Log.i(TAG,"---------------onRestart---- 重新启动--------");
}
}
打开应用:创建onCreate --> 开始onStart-->运行onResume
返回应用:暂停onPause --> 停止onStop-->销毁onDestroy
:暂停onPause --> 停止onStop
重新打开应用:重新启动onRestart--> 开始onStart-->运行onResume
跳转页面时:当前页:暂停onPause --> 停止onStop,跳转新页面:创建onCreate --> 开始onStart-->运行onResume,返回时:跳转新页面:暂停onPause --> 停止onStop-->销毁onDestroy,返回当前页:重新启动onRestart--> 开始onStart-->运行onResume