Friday, April 15, 2011

ANDROID: Activity as a web page

Mobile apps creation are somewhat similar to web apps. The major difference is memory available. But here I am going to discuss more on similarity. Lets start with the basic:

Activity as a web page:

Activity is like a web page on the web application. Each activity is a web page. Whenever u launch the application, one main activity gets displayed and which can start other activities. In this case the previous activity is stopped, and similar to web app where a browser keeps the previous page which u can go back by pressing back button. Here the operating system preserves the prev acitivity in a "stack".

 

So whenever a new activity starts it goes into stack and when u press back button it will be taken out and destroyed and will not be saved unlike browsers which have Next button.

 

When the activity is stopped it received the callback methods informing abt its state and the action taken by OS for the activity.

 

IMP: Whenever an activity is stopped, it should release the resources (eg. Db and network connections). The activity can again acquire the resources and actions when it get resumes.

 

So basically every app starts with coding of main activity which is a class which extends the activity class and defines its callback methods (onCreate, onPause etc.) which will be similar to your home page.

 

For more technical details about creating, stopping, invoking another activity, and different states of the acitivity, please refer to the link: http://developer.android.com/guide/topics/fundamentals/activities.html