Pages

Monday 17 February 2014

Android LifeCycle

Android is designed around the unique requirements of mobile applications. In particular, Android recognizes that resources (memory and battery, for example) are limited on most mobile devices, and provides mechanisms to conserve those resources. The mechanisms are evident in the Android Activity Lifecycle, which defines the states or events that an activity goes through from the time it is created until it finishes running.

    Source:O'Reilly Book


onCreate:

Called when your activity is first created. This is the place you normally create your views, open any persistent datafiles your activity needs to use, and in general initialize your activity. When callingonCreate, the Android framework is passed a Bundle object that contains any activity state saved from when the activity ran before.

onStart:

Called just before your activity becomes visible on the screen. Once onStart completes, if your activity can become the foreground activity on the screen, control will transfer to onResume. If the activity cannot become the foreground activity for some reason, control transfers to the onStop method.

onResume:

Called right after onStart if your activity is the foreground activity on the screen. At this point your activity is running and interacting with the user. You are receiving keyboard and touch inputs, and the screen is displaying your user interface.

onPause:

Called when Android is just about to resume a different activity, giving that activity the foreground. At this point your activity will no longer have access to the screen, so you should stop doing things that consume battery and CPU cycles unnecessarily.

onStop:

Called when your activity is no longer visible, either because another activity has taken the foreground or because your activity is being destroyed.

onDestroy:

This onDestroy method is used to destroy the activity, it is the last chance.its finish method.


No comments:

Post a Comment

Search Form