Android App Components

Android app is written in Java programming language (mostly). Java code is compiled together with the resource file data required by the application, where the process is packaged by tools called as “apt tools” into the Android package so that it generates files with apk extension. Apk file that’s what we call the application, and later can be installed on mobile devices.

There are six types of components in the Android app that are:

  1. Activities

    An activity will present the user interface (UI) to the user, so the user can interact. An Android app can only have one activity, but generally the application has a lot of activity depending on the application’s purpose and the design of the app. One activity will usually be used to display an application or acting as a user interface (UI) when an application is shown to the user. To move from one activity to another activity we can do it with one event, for example, click the button, choose an option or use certain triggers. Hierarchically a windows activity is expressed by the Activity.setContentView () method. ContentView is an object located in the root hierarchy.

    Activities:

    • Provides User Interface
    • Usually represents a Single Screen
    • Can contain one/more Views
    • Extends the Activity Base class
  2. Service

    Service does not have a Graphics User Interface (GUI), but the service runs in the background, for example in playing music, the service may play music or retrieve data from the network, but each service must be in its parent class. For example, the media player is playing a song from an existing list. This app will have two or more activities that allow the user to select songs for example, or write SMS while the player is running. To keep music running, activity player can run service. Service runs on the main thread of the application process.

    Service:

    • No User Interface
    • Runs in Background
    • Extends the Service Class
  3. Broadcast Receiver or Intent

    Broadcast receiver functions are to receive and react to convey notification. Examples such as change of time zone notification, low battery, Image that have taken by the camera, or changing language reference that is used. Applications can also initiate broadcasts, for example providing information on other applications that there is data that’s downloaded to the device and ready for use.Broadcast receivers do not have a user interface (UI), but have an activity to respond to information they receive, or may use Notification Manager to notify users, such as backlights or vibrating devices, and so on.

    Broadcast Receiver/Intent:

    • Receives and Reacts to broadcast Intents
    • No UI but Can Start an Activity
    • Extends the BroadcastReceiver Base Class
  4. Content Provider

    Content provider creates a specific set of application data so that it can be used by other applications. Data stored in system files such as SQLite.Content provider database provides a way to access data required by an activity, eg when we use applications that require the map, or applications that require access to contacts and navigation data, this is where the content provider’s  function.

    Content Provider:

    • Makes application data available
    • Data stored in SQLite database
    • Extends the Content Provider Base class