Implementing the Life Cycle of an Activity

1

Hello. I'm new to Android Development and would like to better understand how to build more robust applications for this platform. I understand how the life cycle of a Activity works but I wanted to understand how to structure my applications better by following best practices for doing so.

  • Which of the lifecycle methods should be used to build the Graphical User Interface? I mean, instantiate all Views and assign their respective behaviors. Only the onCreate method or other methods can also be used?

  • At what point should I use onStart and onResume ?

  • asked by anonymous 08.10.2018 / 09:49

    1 answer

    3

    Basically, Activity's lifecycle methods have their times of execution.

    See below:

    onCreate() : This is the first function to execute in an Activity. It is usually responsible for loading XML layouts and other initialization operations. It is executed only once;

    onStart() : Is called immediately after the onCreate () - and also when an Activity that was in the background returns to focus,

    onResume() : Just like onStart (), it is invoked at Activity initialization and also when Activity returns to focus. What's the difference between the two? OnStart () is only called when Activity was no longer visible and resumes focus, onResume () is called in "focus resumes";

    onPause() : This is the first function to be invoked when the Activity loses focus (this occurs when a new Activity is started);

    onStop() : Only called when Activity is completely hidden by another Activity;

    onDestroy() : The last function to execute. After it, Activity is considered "dead" - meaning it can not be re-released. If the user re-requests this Activity, a new object will be constructed;

    onRestart() : Call immediately before onStart (), when an Activity returns to focus after it is in the background.

    Source: Article Understanding the life cycle of an Android application | DEVMEDIA

        
    08.10.2018 / 09:58