Friday, 14 May 2010

Creating Activity

Q. What is Activity in android?
Activity is a super class, which contains the java code that supports a screen or UI. In other words, building block of the user interface is the activity.
 Every application which has UI must inherit it to create window.

Q. Creating the Activity?

Ans:  The following steps are involved while we are creating the Activity
step1: while we are creating the Activity class(our own user defined class) must be a sub class of Activity class.

public class MainActivity extends

Step 2: provide the implementation for the onCreate() method
public class MainActivity extends
public void onCreate(Bundle savedInstanceState)
  //call the super class method
 //specify the xml file
}//end of onCreate()

Q. why should we extend the super class Activity?
Ans: to manage the Life cycle of activity.

Q. What are the Activity Life Cycle?

It has 4 states:
1. Does not exist state
2. ForeGround state
3. Background state
4.Activity pause

Q; What are the methods are available in Activity class?


  1. onStart()
  2. onPause()
  3. onResume()
  4. onRestart()
  5. onStop()
  6. onDestroy()
Q: What are the 4 states of activity class

No comments:

Post a Comment