Android Development - Android Activity Classes Explained In Detail

in Activity
As a fledgling Android developer one of the first things you'll need to do is get your head around Activity Classes. We can't overstate the importance of this. A sharp, fluid understanding of how each class interacts with each other class, and the end result for end users will not only speed along your project dev time, but open up new possibilities for your programming. So let's take a look at these in some detail.

onCreate(): This is called when the activity first starts up. You can use it to perform one-time initialization such as launching the user interface. onCreate() utilizes one parameter that is either null or state information previously saved by the onSaveInstanceState( ) method, discussed below.

onStart(): This indicates the activity is about to be displayed to the user.

onResume(): This is called when the user can start interacting with the activity. This is a good place to start animations and music.

onRestart(): If this is called, it indicates your activity is being redisplayed to the user from a stopped state.

onFreeze(): Allows you to save your current state when one activity is being paused and another one resumes to interact with the user. After being paused, the system may at any time need to stop (or even outright kill) your application in order to claim resources for the current foreground activity. If this should happen, the state you supply here will later be recalled with
onCreate(), when the user starts a new instance of your activity.

onPause(): This runs when the activity is about to go into the background, usually because another activity has been launched in front of it. This is where you should save your program's persistent state, such as a database record being edited.

onStop(): This is called when your activity is no longer visible to the user and it won't be needed for a while. If memory is tight, onStop() may never be called (the system may simply terminate your process).

onDestroy(): This is called right before your activity is destroyed. If memory is tight, onDestroy( ) may never be called (the system may simply terminate your process).

onSaveInstanceState(Bundle): Android calls this method to allow the activity to save per-instance states, such as a cursor position within a text field. Usually you won't need to override it because the default implementation saves the state for user interface controls automatically.

onRestoreInstanceState(Bundle): This is called when the activity is being reinitialized from a state previously saved by the onSaveInstanceState() method. The default implementation restores the state of your user interface.

I hope this brings you up to speed on Android Activity Classes. The more familiar you are with Activity Classes and how and they affect the end user experience, the more successful your Android apps development will be.
Author Box
Allie has 1 articles online

Author Resource:

Sourcebits is a professional iPhone, iPad and Android Developer. We have the expertise and unmatched experience in Android Development. We build best-selling applications tailored to client specifications for various platforms like iPhone, iPad, Android, BlackBerry, and Palm Pre.

Add New Comment

Android Development - Android Activity Classes Explained In Detail

Log in or Create Account to post a comment.
Security Code: Captcha Image Change Image
This article was published on 2011/01/05