Activity




An Activity is a class that represents an Object to control the screen. It is your main program and you can have other Activities for other screens.

Example:

  

package com.MySample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.*;

public class MySample extends Activity {
   // put instance variables here
   ImageButton myImageButton;
  
  
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    
     // we will use the main.xml file to create all of our
     // UI objects and display them on the screen
     setContentView(R.layout.main);
    
     setTitle("Title under status bar");
    
     // put other initialization stuff here
     // references to your UI objects would get initialized here
     // All UI objects are declared in the layout file main.xml
     // You may have several different screen views in other xml files
     // that are created by the Activity setContentView(R.layout.main);
     // you can call the findViewById method to get their memory location
    
     myImageButton = (ImageButton) findViewById(R.id.ImageButton01);
    
   }
  
   // put other methods here
  


}