Learning Android – Part 1: Intro and The four components

· Tech · , ,

Intro

When learning a new programming paradigm, language or framework, there a different ways to approach the challenge. Somebody do prefer “Learning by doing”, but I personally prefer knowing the theory before actually doing any coding. That way I’m approaching the challenge from bottom to top, and not the other way around. Before going into the theory itself it is strongly recommended to know some basic Java programming. I’m first going through the theory around general parts of Android and then later on some specific code snippets which do require some basic Java knowledge.

The four components

Each application runs in its own virtual machine called Dalvik Virtual Machine (DVM). The Android operating system consists of four main components called; Activity, Service, Content Providers and Broadcast Receivers. An activity is an operation that is visual for the user – example: to show a menu screen in a Sudoku game. Service, unlike Activity, is not visual for the user and it is used for long running operations such as downloading information form the internet or doing heavy calculations. It is important to mention that a Service is not a sperate process nor it is a thread. Content Providers manages a set of application data. Using the file system or SQLite are typical examples of Content Providers. The last component is the Broadcast Receiver which both can send and respond to system-wide broadcast announcements called Intents.

The Android operating system is using a asynchronous message called Intents to activate components such as Activity or Service. Intents bind individual components to each other at runtime. With Intents you define the action (what to do) and may specify the URI (the data to act on). Example: the URI can be a telephone number while the action can be Android’s predefined activity action such as “ACTION_DIAL”. Together you combine them in an Intent object which is sent to the operating system. Content providers are not activated by Intents. They use rather Content Resolvers which sends a request. Content Resolvers manage all direct transactions with the Content Providers.

Learning Android – Part 2: The Manifest file, Activity stack, and Layout

Written by almirmesic · · Tech · , ,