Thursday, 14 November 2013

Activity and its Lifecycle Methods

Each Screen in an Android Application is called an Activity.
If you want to build a screen, you need to extend and Activity in other words you need to write a class and
that should be a sub-class of Activity.

Before we go on to how we build a screen, we shall need to have some knowledge of how an activity works.

The Following are the Lifecycle methods of an activity.


1) onCreate
2) onStart
3) onRestart
4) onResume
5) onPause
6) onStop
7) onDestroy


OnCreate is called when the Activity is first created, Here is where in you shall load the UI you want to present to the user.
We shall look into how to build the UI in subsequent chapters.

When your Activity is partially visible or a Dialog is on top of your screen, that screen or Activity is in a paused state and onPause gets called.
When the dialog disappears or your activity becomes completely visible onResume is called.

If your Activity is completely hidden by another activity or your app is in the Background, the Activity shown in the app is a stopped state and onStop gets called.

An Activity is destroyed if the application is destroyed or the Android System destroys the Activity if it feels it is low on memory. In that case onDestroy is called.
You can do 'clean up' in onDestroy.


When An application is launched, the Main Activity(First Activity to be Shown) is called. The Sequence that it goes through is onCreate-->onStart-->onResume.


Note 1:
   When you create an Activity implementing the onCreate method is mandatory because you have to load the UI.
Implementing the rest of the methods is optional.

Note 2:
  When implementing methods like onPause, onResume, onStop, onDestroy, calling the super method is mandatory as follows:

public void onPause(){

super.onPause(); //This call to super is mandatory

}

public void onResume(){

super.onResume(); //This call to super is mandatory

}
If you do not call the super method the app crashes, that's the way it has been designed do not ask me.
So the Next chapter will be about building UIs that you shall be loading in onCreate







Tuesday, 22 October 2013

The Basics of Android Development - Application Components

                                                         Application  Components


"A program is written well when you can understand what  the program does just by looking at the code -  Anonymous".

An Android application is made up of Building blocks called Application components.There are 4 application components in Android, they are:

1) Activity.
2) BroadcastReceiver.
3) Services.
4) Content Providers.

Activity: Each Screen in an Android App is an Activity.  An activity is a window on which you can
place UI elements like TextFields, Images, Buttons, Lists etc.

BroadcastReceiver: As the Name Suggests A broadcast receiver is meant to receive broadcasts. Broadcasts are messages/events that are broadcaste either by the system or by other applications or by components within your own application.

Use cases for BroadcastReceiver:
       Passing messages within your Application; you can send a message from one module and receive it in another module. very handy for event handling in apps.

System regularly send broadcasts w hen Battery is down, Network goes down or network comes up, Aeroplane mode is switched on or switched off.
You can receive these system broadcasts  if you want to handle a particular scenario(like Network Down) within your app.

Services: Service is used to perform long running background tasks for example something like a file download from a server. Please note that the Service is not a 'Thread' and is not meant to do tasks in an asynchronous manner.
Another use of Service is that it can provide for IPC(Inter Process communication/Client-Server) facility for android apps.

We shall revisit the important and meaty concept of Service in a separate dedicated chapter.


ContentProviders: As the Name suggests the use of content providers is when you want your application to provide access of its data to other apps.
Basic Applications like Contacts, Calendar, Browser etc provide content via Content-Providers, now you know how applications like WhatsApp or WeChat get access to your phone contacts.

We end this blog here for today, Stay tuned for more tutorials from this Blog folks, much more to share and much more to learn...

Quote Corner:

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds 


Monday, 21 October 2013

The Basics of Android Application Development - Introduction

                                 The Basics of Android Application Development


Preface:

You should already find a whole lot of Android tutorials online, however the Objective of this particular Blog Series is to make learning of Android Application Development as easy as possible and explain the most relevant topics concerned with Android Application Development.
Even a School Kid should be able to learn from this blog.

A Really Small Description of Android
Android is Software Stack consisting of Linux Kernel, SDK(Software Development Kit) to develop apps and some pre-loaded applications(Contacts, Calendar, Browser etc)


The Architecture of Android
Linux Kernel (Device Drivers) come at the Bottom, On top of is the  layer that consists of  some core c libraries like opengl, webkit, ssl, libc etc.
On top of the Library Layer is the Application Framework which consists a lot of  Managers like WifiManager, Telephony Manger, ActivityManager etc. We shall revisit these managers later in the blog series.
On top of the Application Layer, the  applications are loaded.

Here is a  Graphical View of the Architecture of Android

Tools Required for Apps Development

Eclipse, Android SDK(Available here), Android NDK(not mandatory)


NDK - Native Development Kit is required only when one needs to use C/C++ libraries in a project.

In the Next Chapter we shall directly dig into Apps Development.