Android Activity Life Cycle

Muthinja
2 min readDec 2, 2018

--

I guess many beginner android developers overlook this here.

Being a beginner android developer in this day and time is quite hard. Yes I know a lot of people say contrary, but if you look at the frameworks, tools and even our IDE’s themselves do a fair share of work we do. This has led a lot of beginner developers a stray, thinking development can and should be easier, ignoring what happens under the hood. One major and often misunderstood concept in android development is the activity life cycle.

As an android developer all you need to know to create fairly standard applications is how to create a project, create an activity, create intents to communicate between in app and outside activities, a little bit of java code and a bunch of youtube tutorials. But wait, this does not mean developing android apps is easy. My aim is to address what many developers overlook to enable you and I have a better understanding on android.

The activity life cycle is basically a briefly under rated term defining what happens when you open your applications activity, stop working with them, change screen orientation or even when you close the app. When you click an app icon on you launcher, your app launches, the android manifest is checked to see the launcher activity. Android then checks to see if the apps process is in memory if not creates it and launches your activity. Once launched the onCreate() method is called to draw your layout.xml file containing views you need. Later on onStart() is called to signify that you activity is starting and all you views are created. Afterwards onResume() is called once the user start interacting with your app. When you want to navigate to another activity your initial activity onPause() and onStop() methods are called, here all processes in your activity are on halt. Afterwards android checks if the target activity is in the same process and calls the onCreate() method if the activity is not in memory ,and the cycle is the same for the activity. If you navigate back to the activity, onRestart() is called if the activity is still in memory, onStart() and onResume() are later next in line.The most crucial method i think is the onDestroy() method ,it confuses a lot of developers.It is called when you app needs to be terminated either by the user or the system for memory allocation to other processes.It is called also when screen orientation changes and you need to retrieve the activities current state.

I hope this article has helped you not only in android but also in life as a developer. If any remarks email me at collinsmuthinja@gmail.com

Happy Coding ;-)

--

--

Muthinja
Muthinja

Written by Muthinja

Co Founder & CTO Tripitaca. Building an online booking platform with embedded finance

No responses yet