Android Activity Lifecycle

 

              "Android Activity Lifecycle"

if we are new to Android development then we should learn what an Activity is in Android and what is the lifecycle of an Activity. In this blog, we will learn about,

  • What is the Activity Lifecycle?

Activity Lifecycle :


To understand the activity lifecycle, consider an example of a human being. As human beings, we go through certain stages of our life starting from as a kid to a teenager. From an adult and then to an old person. These are the phases or states of life we go through.

Similarly, for Activity in Android, we go through state changes in the total duration of the activity.

An Android activity undergoes through a number of states during its whole lifecycle. The following diagram shows the whole Activity lifecycle:

                                                                                                                                        The Activity lifecycle consists of 7 methods:

  1. onCreate() : When a user first opens an activity than the first method that gets called is called as onCreate. It acts the same as a constructor of a class, then when an activity is instantiated then onCreate gets called.
  2. onStart(): This method is called when an activity becomes visible to the user and is called after onCreate.
  3. onResume(): It is called just before the user starts interacting with the application.
  4. onPause():  It is called when the app is partially visible to the user on the mobile screen.
  5. onStop(): It is called when the activity is no longer visible to the user.
  6. onRestart(): It is called when the activity in the stopped state is about to start again.
  7. onDestroy(): It is  called when the activity is cleared from the application stack.
So, these are the 7 methods that are associated with the lifecycle of an activity.

Hope you learned something new today.

Have a look at our Android Tutorials.

Do share this Blog  with your fellow developers to spread the knowledge. You can read more blogs on Android on our blogging website.

Happy Learning :)

-----------------------------------------------------------------------------------                       Share this blog to spread the knowledge

Comments

Popular posts from this blog

🔥 Java Exception and Error Handling

Understanding How OOP Concepts Work with Real-Life Examples

🌿⚙️ Spring Boot Simplified