Please explain the lifecycle of an Activity?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Jun 11, 2024

 

Android is an open-source operating system that can be useful for many tasks. An android application will undergo various states that are associatively called as Android Activity Life Cycle.

The lifecycle of activity consists of 7 methods:-

  1. onCreate() - The function onCreate() is called When a user first opens an activity that acts the same as a constructor of a class. 
  2. onStart() - The function onStart() is called when an activity becomes visible to the user and is called after onCreate.
  3. onResume() - The function onResume() is called just before the user starts interacting with the application.
  4. onPause() - The function onPause() is called when the app is partially visible to the user on the mobile screen.
  5. onStop() - The function onStop() is called when the activity is no longer on the activity stack and not visible to the user.
  6. onRestart() - The function onRestart() is called when the activity in the stopped state is about to start again.
  7. onDestroy() - The function onDestroy() is  called when the activity is cleared from the application stack.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Android Interview Questions

    What is Android?

    Android, built on the Linux kernel, is an open-source operating system used in smartphones and tablets. Its high-performance components empower developers to create and execute apps with diverse funct..

    Android Interview Questions

    What are the Android application components?

    Android application components, including Activities, Services, Broadcast Receivers, and Content Providers, form the foundational elements of Android apps. These components facilitate various function..

    Android Interview Questions

    What does Fragment mean?

    Fragments in Android represent modular UI components within a FragmentActivity. They enable the creation of flexible and reusable UIs by combining multiple fragments within a single activity. Each fra..