This document provides an overview of Android development including the key components of an Android app. It discusses Activities, Services, Content Providers, Broadcast Receivers, Intents, Views, and common UI elements. It also covers how to start Android development using Android Studio and best practices for handling the UI thread and asynchronous tasks. Notifications are demonstrated as well key layout types and the Play Store.
2. Agenda
Why mobile development?
The good and bad of android
How to start with Android Development
App Components
Types of layouts
Input controls
UI Thread
Notifications
8. How to start with Android Development
Android apps are written in the Java programming language.
The Android SDK tools compile your code into an APK.
The Android operating system is a multi-user Linux system in which each app is a different
user.
However, there are ways for an app to share data with other apps and for an app to access
system services:
It's possible to arrange for two apps to share the same Linux user ID.
An app can request permission to access device data such as the user's contacts, SMS
messages, the mountable storage (SD card), camera, Bluetooth, and more. All app
permissions must be granted by the user at install time.
9. Android Manifest
Describes the components of the application. It names the classes that implement each of
the components and publishes their capabilities (for example, which Intent messages they
can handle). These declarations let the Android system know what the components are
and under what conditions they can be launched.
It declares which permissions the application must have in order to access protected parts
of the API and interact with other applications.
It also declares the permissions that others are required to have in order to interact with
the application's components.
17. Activities
An Activity is an Application component that provides a screen with which users can
interact.
Each activity is given a window in which to draw its user interface.
An application usually consists of multiple activities.
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.
Each activity can then start another activity in order to perform different actions.
Each time a new activity starts, the previous activity is stopped, but the system preserves
the activity in a stack (the "back stack").
19. Services
A Service is an application component that can perform long-running operations in the
background and does not provide a user interface.
Another application component can start a service and it will continue to run in the
background even if the user switches to another application.
Additionally, a component can bind to a service to interact with it and even perform
interprocess communication (IPC). For example, a service might handle network
transactions, play music, perform file I/O, or interact with a content provider, all from the
background.
21. Content providers
A content provider manages a shared set of app data. You can store the data in the file
system, an SQLite database, on the web, or any other persistent storage location your app
can access.
Through the content provider, other apps can query or even modify the data (if the
content provider allows it).
For example, the Android system provides a content provider that manages the user's
contact information. As such, any app with the proper permissions can query part of the
content provider to read and write information about a particular person.
Content providers are also useful for reading and writing data that is private to your app
and not shared.
23. Broadcast receiver
A broadcast receiver is a component that responds to system-wide broadcast
announcements.
Many broadcasts originate from the systemfor example, a broadcast announcing that
the screen has turned off, the battery is low, or a picture was captured.
Apps can also initiate broadcastsfor example, to let other apps know that some data has
been downloaded to the device and is available for them to use.
Although broadcast receivers don't display a user interface, they may create a status bar
notification to alert the user when a broadcast event occurs.
25. Intents
Intents bind individual components to each other at runtime, whether the component
belongs to your app or another.
For activities and services, an intent defines the action to perform (for example, to "view"
or "send" something) and may specify the URI of the data to act on (among other things
that the component being started might need to know).
In some cases, you can start an activity to receive a result, in which case, the activity also
returns the result in an Intent.
For broadcast receivers, the intent simply defines the announcement being broadcast.
27. Views
All user interface elements in an Android app are built using View and ViewGroup objects.
A View is an object that draws something on the screen that the user can interact with.
A ViewGroup is an object that holds other View (and ViewGroup) objects in order to
define the layout of the interface.
Android provides a collection of both View and ViewGroup subclasses that offer you
common input controls (such as buttons and text fields) and various layout models (such as
a linear or relative layout).
28. Input controls
Buttons
Text Fields
Checkboxes
Radio Buttons
Toggle Buttons
Spinners
Pickers
36. UI Thread
It is in charge of dispatching events to the appropriate user interface widgets, including
drawing events.
Interacts with components from the Android UI toolkit
There are simply two rules to Android's single thread model:
Do not block the UI thread
Do not access the Android UI toolkit from outside the UI thread
37. AsyncTask
onPreExecute: Invoked before the task is executed ideally before doInBackground
method is called on the UI thread. This method is normally used to setup the task like
showing progress bar in the UI.
doInBackground: Code running for long lasting time should be put in doInBackground
method. When execute method is called in UI main thread, this method is called with the
parameters passed.
onProgressUpdate: Invoked by calling publishProgress at anytime from doInBackground.
This method can be used to display any form of progress in the user interface.
onPostExecute: Invoked after background computation in doInBackground method
completes processing. Result of the doInBackground is passed to this method.