Home > DeveloperSection > Interviews > Describe android Activities in brief.

Posted on    May-28-2015 11:37 PM

 Android Android  Android Activity 
Ratings:
 1 Answer(s)
  403  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    May-28-2015 11:37 PM

Activity provides the user interface. When you create an android application in eclipse through the wizard it asks you the name of the activity. Default name is MainActivity. You can provide any name according to the need. Basically it is a class (MainActivity) that is inherited automatically from Activity class. Mostly, applications have one or more activities; and the main purpose of an activity is to interact with the user. Activity goes through a number of stages, known as an activity’s life cycle.

Example:

package com.example.careerride; //Application name careerride
import android.os.Bundle; // Default packages
import android.app.Activity; // Default packages
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;

}

When you run the application onCreate method is called automatically.


Modified On May-28-2015 11:47:30 PM

Don't want to miss updates? Please click the below button!

Follow MindStick