Jumat, 14 Juni 2024

Android Activity LifeCycle

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, etc.

Android App Activity Lifecycle

When you launch your application, the following methods are executed in order:
  • onCreate
  • onStart
  • onResume
At this point, the activity is visible to the user and they can interact with it. 

In our example, we have a button in Activity A that allows the user to navigate to Activity B.
When the user clicks the button, the following methods are executed:
  • onPause (in Activity A)
  • onCreate (in Activity B)
  • onStart (in Activity B)
  • onResume (in Activity B)
Now, Activity B is visible to the user and they can interact with it. Activity A is in the paused state.
If the user presses the back button, the following methods are executed:
  • onPause (in Activity B)
  • onStop (in Activity B)
  • onRestart (in Activity A)
  • onStart (in Activity A)
  • onResume (in Activity A)
Now, Activity A is visible to the user again and they can interact with it. Activity B is destroyed.
If the user presses the back button again, the following methods are executed:
  • onPause (in Activity A)
  • onStop (in Activity A)
  • onDestroy (in Activity A)
Now, both Activity A and Activity B are destroyed and nothing appears on the screen.

Bibliography

https://blog.stackademic.com/
https://developer.android.com/
https://medium.com/
https://www.tutorialspoint.com/

Related Post

Tidak ada komentar:

Posting Komentar