Mad 17
Mad 17
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="Hello World!" />
</RelativeLayout>
MainActivity.java:
package com.example.pr_16;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MainActivity", "onCreate() called");
}
@Override
protected void onStart() {
super.onStart();
Log.d("MainActivity", "onStart() called");
}
@Override
protected void onResume() {
super.onResume();
Log.d("MainActivity", "onResume() called");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("MainActivity", "onRestart() called");
}
@Override
protected void onPause() {
super.onPause();
Log.d("MainActivity", "onPause() called");
}
@Override
protected void onStop() {
super.onStop();
Log.d("MainActivity", "onStop() called");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("MainActivity", "onDestroy() called");
}
}
Output:
onPause() onResume()
It is called when the activity is paused It is called just before the user starts
i.e. it is mostly called when you press interacting with the application. Most
the back or home button of your of the core functionalities of the app
Android device. It is an indication that are implemented in this method.
the user is leaving the activity and
starting some other activity.
Called each time the activity is about Invoked every time the activity returns
to lose focus or become inactive. to the foreground.
Activity is still visible but may not Activity is fully visible and ready to
have user focus. interact with the user.