Thursday, January 26, 2012

Android Basics

Lets starts with the basic of Android i.e Activity life cycle. Each android java class extends with Activity class and it should be with proper implementation of each step need to be done to provide a complete and full life cycle of that activity and it also gives seamless running of the application.At the same time we can also write our application without all the steps involved in life cycle of activity but it will not give proper structure of code and also sometimes leads to exception of the application.

Activity Life Cycle

Activity Launched -- onCreate() -- onResume() -- onPause() -- onDestroy()

Apart from above methods, start and stop, onRestart methods are also available but it is not much as important as above methods.

Each class in Android must extend Activity class to create an application.When activity gets started the first method onCreate() will be called in that we need to set the content view with the XML layout for UI design components.

Then onResume() method will be called when activity is again invoked i.e. navigate to previously opened activity.

onPause() method will be invoked when the activity gets navigation action, the current activity will be in pause state without doing any performance.

onDestroy() method is used to destroy the current activity.

No comments: