Android Activities

Each Activity represents a screen that an application can present to its users. The more complicated your application, the more screens you are likely to need

Typically, this includes at least a primary interface screen that handles the main UI functionality of your application. This primary interface generally consists of a number of Fragments that make up your UI and is generally supported by a set of secondary Activities. To move between screens you start a new Activity (or return from one).

Most Activities are designed to occupy the entire display, but you can also create semitransparent or floating Activities.

Creating Activities

package com.paad.activities;
import android.os.Bundle;
public class MyActivity extends Activity {
 /** Called when the activity is first created. */
 public void onCreate(Bundle savedInstanceState) {

The base Activity class presents an empty screen that encapsulates the window display handling. An empty Activity isn’t particularly useful, so the first thing you’ll want to do is create the UI with Fragments, layouts, and Views

Views are the UI controls that display data and provide user interaction. Android provides several layout classes, called View Groups, which can contain multiple Views to help you layout your UIs. Fragments are used to encapsulate segments of your UI, making it simple to create dynamic interfaces that can be rearranged to optimize your layouts for different screen sizes and orientations

To use an Activity in your application, you need to register it in the manifest. Add a new activity tag within the application node of the manifest; the activity tag includes attributes for metadata, such as the label, icon, required permissions, and themes used by the Activity. An Activity without a corresponding activity tag can’t be displayed — attempting to do so will result in a runtime exception.

<activity android:label=”@string/app_name”

Leave a Comment