0% found this document useful (0 votes)
7 views2 pages

Pr-4 61

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Pr-4 61

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mobile Application Development[3170726]

Date:05/09/2024

Practical : 4
AIM : Implement activity Lifecycle and State Callbacks

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:id="@+id/main"
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="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

package com.jash62.pr6;
import android.os.Bundle;
import android.util.Log;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
Log.d("Event","In the onCreate() event");
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
public void onStart() {
super.onStart();

210760107062 24
Mobile Application Development[3170726]

int event = Log.d("Event", "In the onStart() event");


}
public void onRestart() {
super.onRestart(); int event = Log.d("Event", "In the onReStart() event");
}
public void onResume() {
super.onResume();
int event = Log.d("Event", "In the onResume() event");
}
public void onPause() {
super.onPause();
int event = Log.d("Event", "In the onPause() event");
}
public void onStop() {
super.onStop();
int event = Log.d("Event", "In the onStop() event");
}
public void onDestroy() {
super.onDestroy();
int event = Log.d("Event", "In the onDestroy() event");
}
}

Output:

210760107062 25

You might also like