You are on page 1of 21

What Androids are Made of

Main Building Blocks


Android building blocks make it easy to break down an application into conceptual units, work on them independently and easily put them together into a complete package
Activities Services Intents Broadcast receivers Content providers

Activities
A single screen that a user can see An application typically has multiple activities Concept of activities can be easily understand by comparing an Android application with a website

Activity Life Cycle


Activity life cycle is managed by Activity Manager

Activity Life Cycle


Starting State
When an activity doesnt exist in memory After starting state, an activity enters the running state Transition from starting state to running state is one of the most expensive operations in terms of computing time and battery life

Activity Life Cycle


Running State
When an activity is currently on the screen and interacting with the user Meaning that the activity is in focus There is only one running activity at any given time

Activity Life Cycle


Paused State
When an activity is not in focus But it is still visible For example, a dialog box coming in front of an activity can cause the activity to pause Paused activities still have high priorities in terms of getting memory and other resources

Activity Life Cycle


Stopped State
When an activity is not visible, but still in memory A stopped activity can be moved back to either the running state or it could be destroyed Why do you think the system keeps activities in stopped state?

Activity Life Cycle


Destroyed State
When an activity is no longer in the memory Before an activity gets destroyed, it can perform certain actions, such as saving unsaved data. Remember, there is no guarantee that an activity will be stopped before being destroyed Therefore, it is important to do important stuff, such as saving data, en route to a paused state.

Intents
Messages that are sent among the major building blocks (for example, to start or stop an activity or service) Intents are asynchronous Could be explicit (the sender clearly mentions a specific receiver) or implicit (the sender mentions the type of receiver)

Intents Example

Services
Run in the background and dont have any user interface components Useful for actions that we want to perform for a while, regardless of what is on the screen For example, listening music while flipping between applications

Service Life Cycle


Services have a much simpler life cycle than activities

Content Providers
Interfaces for sharing data between applications Data that belongs to an application is usually isolated Although we also use intents for sharing information, content provider are suited for large datasets

Content Providers

Content Provider Example

Broadcast Receivers
Androids implementation of a system-wide publish/subscribe mechanism. They are also called observer patterns The receiver is a piece of code that gets activated once an event to which it has subscribed occurs

Application Context
Android major building blocks together make up an application They live inside the same application context Application context refers to the application environment It gets created whenever first component of an application starts (that component can be any building block) Reference to context can be obtained
Context.getApplicationContext() Activiy.getApplication()

How to get Started?

Step # 1: Java
When you write Android applications, you typically write them in Java source code. That Java source code is then turned into the stuff that Android actually runs (Dalvik bytecode in an APK file). Hence, the first thing you need to do is get set up with a Java development environment and be ready to start writing Java classes.

Step # 1: Java
This is what we did in the last week

Step # 2: Install the Android SDK

You might also like