• Activity:
    • An activity in Android is a specific combination of XML files and JAVA files.
    • It is basically a container that contains the design file as well as the coding stuff file.
    • Here, XML files act as a front-end tool to provide the interface design of the screen, and JAVA files as a back-end tool to deal with all coding stuff to perform different types of actions.
  • The Activity lifecycle consists of several callback methods that get invoked by the Android system as the Activity transitions through its different states.
  • All the methods of the Android activity belong to android. app.Activity class.
  • The Activity lifecycle represents the various states that an Android Activity goes through during its lifetime.

  • The different core stages of the Android Activity Lifecycle are as follows:-
  1. onCreate():

    • This method is called when the activity is first created.
    • It’s where we perform one-time initialization tasks, such as setting up the user interface (UI), initializing variables, and preparing resources.
  2. onStart():

    • This method is called when the activity becomes visible to the user.
    • At this point, the activity is visible but might not yet be in the foreground, and user interaction is possible.
  3. onResume():

    • This method is called when the activity is about to start interacting with the user. 
    • The activity is now in the foreground and receives user input.
  4. onPause():

    • It is called when the activity loses focus and is no longer in the foreground. This typically happens when another activity is launched or when the device’s screen is turned off. In this situation, the resources are released that are no longer needed, pause animations, and potentially save user data.
    • In other words, we can say that it is called when activity is not visible to the user.
  5. onStop():

    • This method is called when the activity is no longer visible to the user.
    • It can happen when the activity is being pushed to the background or when another activity is launched.
    • Here, we might save important data or perform cleanup tasks.
  6. onRestart():

    • This method is called when the activity is being brought back to the foreground after being stopped.
    • It’s followed by the onStart() and onResume() methods.
  7. onDestroy():

    • This is the final method of the Android Activity lifecycle when the activity is being destroyed.
    • It is called before the activity is destroyed.
    • In this stage, clean up any resources, unregister listeners, and perform any necessary cleanup before the activity is removed from memory.
Categories: Android

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.