0% found this document useful (0 votes)
3 views4 pages

Android Activity Lifecycle Demo

The document contains the XML layout for an Android activity and the corresponding Java code for the MainActivity class. It demonstrates the Android activity lifecycle by logging and displaying Toast messages for each lifecycle method: onCreate, onStart, onResume, onPause, onStop, onRestart, and onDestroy. The layout consists of a single TextView centered in a ConstraintLayout.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Android Activity Lifecycle Demo

The document contains the XML layout for an Android activity and the corresponding Java code for the MainActivity class. It demonstrates the Android activity lifecycle by logging and displaying Toast messages for each lifecycle method: onCreate, onStart, onResume, onPause, onStop, onRestart, and onDestroy. The layout consists of a single TextView centered in a ConstraintLayout.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASBA FARHATH

1NT23CS178
Activity_main.xml
<?xmlversion="1.0"encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
auto"xmlns:tools="[Link]
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="Activity LifeCycle Demo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

[Link]
[Link].prog3;
import [Link];
[Link];
import [Link];
[Link];
publicclassMainActivityextendsAppCompatActivity{ @Ove
rride
protectedvoidonCreate(BundlesavedInstanceState){
[Link](savedInstanceState);
setContentView([Link].activity_main);
Toasttoast=[Link](getApplicationContext(),"onCreate
Called",
Toast.LENGTH_SHORT);
[Link]();
Log.d("lifecycle","onCreateinvoked");
}
@Override
protectedvoidonStart(){
[Link]();
Toasttoast=[Link](getApplicationContext(),"onStart Called",
Toast.LENGTH_LONG);
[Link]();
Log.d("lifecycle","onStartinvoked");
}
@Override
protectedvoidonResume(){
[Link]();
Toasttoast=[Link](getApplicationContext(),"onResume
Called",
Toast.LENGTH_LONG);
[Link]();
Log.d("lifecycle","onResumeinvoked");
}
@Override
protectedvoidonPause(){
[Link]();
Toasttoast=[Link](getApplicationContext(),"onPause Called",
Toast.LENGTH_LONG);
[Link]();
Log.d("lifecycle","onPauseinvoked");
}
@Override
protectedvoidonStop(){
[Link]();
Toasttoast=[Link](getApplicationContext(),"onStop Called",
Toast.LENGTH_LONG);
[Link]();
Log.d("lifecycle","onStopinvoked");
}
@Override
protectedvoidonRestart(){
[Link]();
Toasttoast=[Link](getApplicationContext(),"onRestart
Called",
Toast.LENGTH_LONG);
[Link]();
Log.d("lifecycle","onRestartinvoked");
}
@Override
protectedvoidonDestroy(){
[Link]();
Toasttoast=[Link](getApplicationContext(),"onDestroy
Called",
Toast.LENGTH_LONG);
[Link]();
Log.d("lifecycle","onDestroyinvoked");
}
}
OUTPUT:

You might also like