Friday, 14 May 2010

Creating Activity

Q. What is Activity in android?
Ans:
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.
Ex:

public class MainActivity extends android.app.Activity
{
}

Step 2: provide the implementation for the onCreate() method
syntax:
public class MainActivity extends android.app.Activity
{
 @override
public void onCreate(Bundle savedInstanceState)
{
  //call the super class method
  super.onCreate(savedInstanceState);
 //specify the xml file
setContentView(R.layout.activity_main);
}//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?
Ans:

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?

Ans:


  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