An Activity is an application component that provides a
screen with which users can interact in order to do something, such as dial the
phone, take a photo, send an email, or view a map. Each activity is given a
window in which to draw its user interface. The window typically fills the
screen, but may be smaller than the screen and float on top of other windows.[1]
An Activity is a screen in which user perform some task. It
might be capturing image, dialing phone number, typing text message etc. These
all are the activities. Almost every screen with which users interact is an activity.
In activity we make the UI by setting method called:
setContentView(View)
There
are mainly two methods which we use in almost every activity:
- onCreate(Bundle): This method initializes your activity. And in this method we invoke setContentView(int). In setContentView(int) method we pass layout resource which creates UI for an activity. And findViewById(int) is the another method which is used in OnCreate(Bundle) to retrieve all the widgets in the UI.
- onPause(): This is required to deal the situation when user is leaving an activity.
Activity Life Cycle:
- onCreate()
- onStart()
- onResume()
- onPause()
- onStop()
- onRestart()
- onDestroy()
Multiple Activities:
Android uses stack mechanism for handling multiple activities.
It puts the activity in stack when other activity is called. And also retrieves
the activities back in the same manner i.e. Last In First Out. It pops up the
recently added activity and destroys it.
Activity 4
|
Activity 3
|
Activity 2
|
Activity 1
|
Android Course in Noida
ReplyDelete