• Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / tutorials / Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment / Activity Lifecycle

Activity Lifecycle

 

 

 

Activity Lifecycle:
The life of an activity is represented or controlled by 7 methods of Activity class.
1) onCreate
2) onStart
3) onResume
4) onPause
5) onStop
6) on Restart
7) onDestroy

onCreate: Called when Activity is first created
onStart: Called when Activity is becoming visible to the user
onResume: Called when Activity is visible and user starts interacting
onPause: Called when Activity is about to be invisible
onStop: Called when Activity is no longer visible to the user
onRestart: Called when Activity is stopped, prior to start
onDestroy: Called before the Activity is destroyed

Table of Contents

Toggle
  • Example for on Restart method:
    • Activity class:
    • AndroidManifest.xml:

Example for on Restart method:

If we move from activity-1 to activity-2 without destroying the activity-1, whenever we come back to activity-1 from activity-2, onRestart method will be called in activity-1. In this case, onCreate will not be called in activity-1. onCreate will be called only if the activity is destroyed means onDestroy is called.

 

Create an Android application describes Lifecycle of the Activity

XML:
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:gravity=”center”
android:orientation=”vertical”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Activity Lifecycle”
android:textSize=”25sp”
android:textStyle=”bold” />

</LinearLayout>

 

Activity class:

public class DemoActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo1);
Log.i(“Activity Lifecycle”, “onCreate method called”);
}

@Override
protected void onStart() {
super.onStart();
Log.i(“Activity Lifecycle”, “onStart method called”);
}

@Override
protected void onResume() {
super.onResume();
Log.i(“Activity Lifecycle”, “onResume method called”);
}

@Override
protected void onPause() {
super.onPause();
Log.i(“Activity Lifecycle”, “onPause method called”);
}

@Override
protected void onStop() {
super.onStop();
Log.i(“Activity Lifecycle”, “onStop method called”);
}

@Override
protected void onRestart() {
super.onRestart();
Log.i(“Activity Lifecycle”, “onRestart method called”);
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.i(“Activity Lifecycle”, “onDestroy method called”);
}
}

 

AndroidManifest.xml:

Register the above activity in AndroidManifest.xml inside <application> tag as follows

<activity android:name=”.DemoActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>

 

 

 

 

tutorials

  • Core Java Tutorial Free online
  • HTML & CSS Tutorials
  • Php tutorials
  • ubuntu tutorials installation download issues etc
  • redis install ubuntu 20.04 with wordpress php redis mysql configuration
  • [INTRO] Ethical hacking / cyber Security / Penetration testing Tutorial -{updates frequently}
  • Android Studio tutorials syllabus Topics Course details #AndroidApplicationDevelopment
    • Options Menu
    • JSON parsing
    • Handling Views
    • RelativeLayout
    • ActionBar
    • ListView
    • Custom List View
    • Dialogs
    • AlarmManager
    • Notifications
    • Vibration
    • WebView
    • Fragments Runtime
    • SQLiteDatabase
    • Bluetooth
    • WiFi
    • Google Maps
    • Handling Activity Back Button
    • AsyncTask
    • Runtime Permissions
    • Logging
    • Activity Lifecycle
    • Toast
    • Service
    • Database with Cursor Adapter
    • SharedPreferences
    • Location
    • Libraries
    • Webservices
    • Creating Activity class
    • Creating XML
    • Registering Activity in AndroidManifest.xml:
    • Steps for creating an Android application:
    • Handling button clicks
    • Identifying Views
    • Getting Text from Views
    • intent with Data
    • Intent
    • Resources Handling in Android
    • Intent with Result Data
    • Broad cast Receiver
    • Fragment
    • Handling Button click by using On Click Listener:
    • Material Design
    • RecyclerView
    • JSON
    • Rename Android Package [with images & video 2020]
    • migrating to androidx (The library & dependency matching)
    • adsense on webview , adsense & admob policies & implementation
  • AUdio Editing Background Noise removal (Audacity, Adobe Premiere Addition, Camtasia Filmora Windows Obs)
  • what is vpn vs proxy vs tor, http vs https, http2, tcp vs udp, kali linux sql source code injection
  • how to create a website free of cost on google
  • CCNA Syllabus pdf (CCNA / CCNP vs devops vs mcsa /MCSE)
  • Redis performance metrics & tuning for nginx apache ubuntu & debian
  • xampp tutorials 2021 installation errors fix wordpress phpmyadmin mysql apache
  • new relic installation linux (infrastructure agent , php, mysql , nginx)
  • new relic mysql install integration - 2 ways fix problems
  • new relic php agent install in 3 steps
  • aws load balancer tutorial
  • git branches merge fetch pull conflicts

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy