What Is An Activity Lifecycle In Android Development?

What Is An Activity Lifecycle In Android Development?

I recall shedding some light on the similarities between developing Android applications and web applications. Today, I will be sharing more insight into how android applications work and some rather interesting things I learned in my brief study of android development. We established what an Activity is yesterday, what we didn't however talk about is how applications work in both the foreground and background. There's something that is referred to as the activity lifecycle.

AN ACTIVITY LIFECYCLE ENCAPSULATES ALL OUR ACTIONS ON AN APPLICATION

The activity lifecycle simply tracks the way an application is used. We have the total lifetime, the visible lifetime and the foreground lifetime which basically encapsulates how we use our android applications. The total lifetime encompasses the use of the android app from start to finish. Recall that there is a difference between switching between apps on your device and closing an application, android allows us to minimise an application and use other applications with the former running in the background.

UNDERSTANDING BASIC APPLICATION BEHAVIOUR

There are apps/widgets that we can see on our screen but aren't being actively interacted with, these applications fall under the visible lifetime in that we can see them but we're not exactly using them because another app is "drawing over them" which basically means we're interacting with another application/pop-up. Foreground lifetime is what encapsulates applications that we're actively interacting with. Say, for example, you're using the LinkedIn Android app to read a post, it would be running foreground. If another application pops up on your screen and partly covers the LinkedIn application such that you need to minimise/close that app to be able to actively use the LinkedIn app, it would mean that the LinkedIn app was pushed to the visible lifetime because another app was "drawn over" the LinkedIn app.

THERE ARE FUNCTIONS RESPONSIBLE FOR MANAGING THE APP LIFECYCLE

Now in terms of code, Android software engineers are able to control what happens to the application at all these stages using declarative functions (which are more or less a block of instructions) known as "OnCreate", "OnStart", "OnResume", "OnPause", "OnStop", "OnRestart", and "OnDestroy". These functions are inbuilt in the Android development environment such that the machine knows what to expect when a developer uses those phrases, the machine also expects that the developer will use the above phrases in the way and manner that it was made to be used.