Posts Tagged ‘Application Components’

Android Application Fundamentals:

Android applications are written in the Java programming language. The Android SDK tools compile the code—along with any data and resource files. All Code resides in a single file that is apk file (android package file).apk file is use to install the app on device .

Each Android application lives in its own world.

The Android operating system is a multi-user Linux system in which each application is a different user.

By default, every application runs in its own Linux process. Android starts the process when any of the application’s code needs to be executed, and shuts down the process when it’s no longer needed and system resources are required by other applications.

Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications.

By default, each application is assigned a unique Linux user ID. Permissions are set so that the application’s files are visible only that user, only to the application itself — although there are ways to export them to other applications as well.

Different applications can share data with each other but there are some conditions:

  • Both applications has same linux user id and they must be run under same linux process.
  • The applications must also be signed with the same certificate.

Application Components:

There are various components of android application which are essential building blocks of applications which are exists as its own entities and plays a specific role. Building blocks of application define the overall behavior of your app. There are four types of components of an application

1) Activities: An activity provides a user interface for a single screen in your application. Activities can move into the background and then be resumed with their state restored. An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the “main” activity, which is presented to the user when launching the application for the first time. If an application is composed of several screens, it has an activity for each screen. when new activity starts a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack.

2) Services: A service is an Android application component that runs in background and has no visual UI. Services are used to perform the processing parts of your application in the background. While the user is working on the foreground UI, services can be used to handle the processes that need to be done in the background. A service can be started by another Android application component such as an activity or other services and it will continue to run in the background even after the user switches to another application. Thus services are less likely to be destroyed by Android system to free resources, than Activities.

 There are two types of services in Android:

  • Unbound Services: It is a type of service which is not bounded to any components. Once started, it will run in the background even after the component that started the service gets killed.
  •  Bound Services: Its bound to other components and runs only till the component to which it is bounded runs.

3) Content providers: Content Provider are used to share data among several applications. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Then through content providers other applications are able to query, access or even modify the data you’ve created, as long as your content provider allows it.

4) Broadcast receivers: A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured and other applications can receive by using Broadcast receiver.

Activating Components:

 Intents: Intents are the activating components. The components — activities, services, and broadcast receivers — are activated by asynchronous messages called intents. An intent is an object that holds the content of the message. There are two types of Intents in Android:

  • Explicit Intents: Explicit intents designate the target component by its name.In explicit Intent, We specify which activity should get active on receiving the intent. These are usually used for application’s internal communications.
  • Implicit Intents: In implicit Intent we are sending a message to the Android system to find a suitable Activity that can respond to the intent. Implicit intents are often used to activate components in other applications.

Manifest file: Every application must have an AndroidManifest.xml file in its root directory. AndroidManifest.xml is a powerful file in the Android platform that allows you to describe the functionality and requirements of your application to Android. The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. It does a number of things:

  • Informing the Android about the application’s components.
  • Declaring the application’s components, such as naming any libraries the application needs to be linked against.
  • Declare the hardware and software features used or required by the application.
  • Declare the minimum API Level required by application
  • Identify any user  permission the application expects to be granted

Please ensure the manifest is packaged with your app and includes the following elements and data:

  • Version Name
  • Uses- sdk
  • Uses-configuration
  • Uses-feature
  • Supports-screens