MainActivity.java activity_main.xml
Copy package com.example.q2_activity_lifecycle_phases;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
String str="LifecycleStates";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(str,"OnCreate State");
}
protected void onStart(){
super.onStart();
Log.d(str,"OnStart State");
}
protected void onRestart(){
super.onRestart();
Log.d(str,"OnRestart State");
}
protected void onResume(){
super.onResume();
Log.d(str,"OnResume State");
}
protected void onPause(){
super.onPause();
Log.d(str,"OnPause State");
}
protected void onStop(){
super.onStop();
Log.d(str,"OnStop State");
}
protected void onDestroy(){
super.onDestroy();
Log.d(str,"OnDestroy State");
}
}
Copy <?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity LifeCycle Process"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>