The Beautiful world of Activities

Activities are the basic components of any Android app. You may ask what exactly is an activity in android? By definition:
An activity represents a single screen with a user interface just like window or frame of Java.
By digging deeper into this definition, we find that it is what helps us draw the user interface. There can be multiple activities, but always only one "Main" or launching activity which is the one the user interacts with when the app is launched for the first time. Activities basically follow state transition patterns, which basically means it goes through a series of steps right from initialization until it is stopped. In very basic layman terms, you can consider an activity lifecycle to be metaphorically similar to a vendor.
As per a vendor's business lifecycle, say to start a business a vendor needs to create the objects of the trade, followed by actually starting to setup the objects of the trade ,then opening up his store for business, followed by ongoing transactions, followed by taking breaks in between when necessary, then returning back to business, followed by stopping for the day, then returning the following day and when the business doesn't work out selling out the store and shutting down for good.

Similarly, an activity is the vendor in this case. You need to first create the activity. This is done in the onCreate() method, where you initialize the essential components of your activity (say objects of trade). That is followed by onStart() method where these objects become visible (opening up the store where these objects are about to become visible to clients) , then you get into the flow where the activity has become visible, which is done through the onResume() method( in this case the objects that are being sold come under focus of the clients), followed by the activity running phase, where the activity is in the running state (our vendor is in business!) , followed by onPause where the activity loses focus (usually due to another activity taking over , in our case analogous to taking breaks) , followed by onStop where the activity is no longer visible( shutting down the store), but can always be restarted as and when required, in which case it goes back to onStart() method (aka opening the store), followed by onDestroy method where the activity gets destroyed( out of business!).

In this way, the entire lifetime of an activity revolves between the call to onCreate() and the onDestroy() states, whereas the visible lifetime starts between the onStart() and onStop() states.
Also, the foreground lifetime of an activity basically happens between the onResume() and onPause() states. The diagram below illustrates the activity lifecycle which we just discussed in brief detail:


There are a ton of processes and commands involved in between the activity-user interaction paradigm, but I'll cover that eventually in subsequent topics. As a final note I would like to state that you don't need to implement all these callback states ,just the ones which ensure the app -user interaction is carried out in the expected way. I will be covering more ground on all the activity related commands for interactions, co-ordination and transitional states as I move along. For now, just know that Activities form the base of the app and are a very essential component to understand to make sure your app works as expected without any issues. 


Welcome to the world of Android

A new beginning, a fresh start or a new challenge, whatever you would like to call it, A couple of years ago, precisely back in 2013 I decided to make the switch to Android. To learn more about this field, to explore it's features and everything that people brag about starting from the basic features which android developer's claim that Apple stole from Android.
I decided to write this blog after being dormant for years to share my knowledge about the basics, to be able to share what I learned  in the simplest way possible as I have done in the past and hey of course teaching is the best form of learning. So without further delay, let's get started.
Now , you would ask me, what is Android? The definition says:

Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets."

But digging deeper into the technical side, as a developer, it's much more than the mere definition listed above. Let's cover the basic diagram as below:


  So, THIS ladies and gents is what Android REALLY is. More like the "organs/layers" of android which make up the whole Android Operating System. Let me give you a very basic definition of each of these layers without going too much in detail.

Application Layer: This is the topmost layer of the Android layer schema. This is where the UI interactions happen between  the user and the device. All basic functions from playing games to making calls, sending texts, etc. is where this layer comes into play. 
Examples are included in the diagram above.

Application Framework Layer: Just below the Application layer lies this layer, where the interactions are managed. From basic functionalities like telephony, location management to complex ones like Resource Management, using Content Providers etc. this is a very important layer for making sure the operations perform smoothly as expected. You can think of this layer as the "delivery" guy in lay man terms who is responsible for making sure the correct thing triggers when certain action is performed on the UI end.

Libraries: Right below the applications framework comes the libraries Layer in the android architectural paradigm. This layer carries libraries which carry a set of rules to help the device in taking care of different types of data. For example: music player recording or playback is done by the Media Framework library. More examples can be found in the diagram above.

Hardware Abstraction Layer: If I would have to grade this layer, I would most probably grade it as the brain of the whole architecture where main components like graphics, audio camera etc. lie. It is the base layer which allows the next couple of layers to interact with the hardware device at a very general or "abstraction" level. 

Linux Kernel: Right at the bottom of the entire architectural stack is the Linux Kernel Layer. It doesn't interact with anyone. It just sits there without a care in the world about users, but you can think of it as the heart of the system.It provides a lot of important features starting from power management, system drivers, security settings etc.as Android system evolved, the linux kernels evolved alongside, starting from basic 1.0 right to Nougat linux kernels have been evolving and improving alternately hand in hand. 

Now, that we have defined android in more technical terms. I think we are all set to journey into the actual world of android apps. Stay tuned for more of my android adventures and blogs!



Followers

Vishwan Aranha. Powered by Blogger.