Professional Documents
Culture Documents
17
I. Practical Significance
An activity represents a single screen with a user interface. For example, an email application
might have one activity that shows a list of new emails, another activity to compose an email,
and one for reading emails.
2.
App_Name/app/src/main/java/package_name/Activities_Go_Here
3.
onStop()
The system will invoke onStop() callback method when an activity no longer visible to the user,
the activity will enter into Stopped state.
onDestroy()
The system will invoke onDestroy() method before an activity is destroyed and this is the final
callback method which received by the android activity.
=========
onPause()
Whenever the user leaves an activity or the current activity is being Paused then the system
invoke onPause() method.
onResume()
When an activity entered into Resumed state, the system invoke onResume() call back method.
In this state activity start interacting with user that means user can see the functionality and
designing part of an application on the single screen.
X. Exercise
(Use blank space provide for answers or attached more pages if needed)
1. Write a program to create a HelloWorld Activity using all lifecycles methods to display
messages using Log.d.
1.
MainActivity.java
package com.jamiapolytechnic.exp171;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
}
@Override
protected void onResume (){
super.onResume();
Log.d(TAG,"On Resume" );
}
@Override
protected void onPause (){
super.onPause();
Log.d(TAG,"On Pause" );
}
@Override
protected void onRestart (){
super.onRestart ();
Log.d(TAG,"On Restart" );
}
@Override
protected void onStop (){
super.onStop();
Log.d(TAG,"On Stop" );
}
@Override
protected void onDestroy (){
super.onDestroy();
Log.d(TAG,"On Destroy" );
}
}
//====================================================================
activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(15) Related(10) (25)