Professional Documents
Culture Documents
Session 1
2016
Outline
Mobile devices
Android OS
Android architecture
Android Studio
Practice
1 / 33
Mobile devices
2 / 33
Overview
• Mobile devices have outsold traditional desktop and laptop
computers continuously for nearly four years at this point.
The definition of “work” on a computer is changing and adapting
to what devices people are buying 1 .
• Shopping goes mobile. Mobile shopping spiked 60 percent this year
(2015) 2 .
1
www.zdnet.com/article/when-mobile-takes-over-pc-desktops-laptops/
2
www.comscore.com/Insights/Videos/Interview/Shopping-goes-mobile-Mobile-shopping-spiked-60-percent-this-year
3 / 33
Mobile users
• Numbers 3
6
www.netmarketshare.com/operating-system-market-share.aspx?qprid=8&qpcustomd=1
5 / 33
Android OS
6 / 33
Overview
• Android is a mobile OS:
◦ Based on the Linux kernel
◦ Developed by Google.
◦ Designed primarily for mobile devices, such as smartphones and
tablets, but nowadays there are specific versions for:
• Televisions, Cars, and Wear (for wrist watches)
7
www.androidauthority.com/android-everywhere-10-types-of-devices-that-android-is-making-better-57012/
7 / 33
Versions
• Android evolution 8 9
• Android compatibility 10
8
cubettech.com/blog/android-1-0-to-android-m-the-story-of-mobile-evolution/
9
www.android.com/history/#/marshmallow
10
source.android.com/compatibility/index.html
8 / 33
How to develop Android apps
• Android applications are primarily written in the Java programming
language.
◦ During development the developer creates the Android specific
configuration files and writes the app logic in the Java programming
language.
◦ The Android tooling converts these app files, transparently to the
user, into an Android app (an apk file).
10 / 33
Architecture
11 / 33
Runtime
• Each Android app runs in its own security sandbox:
• Each process has its own virtual machine (VM), so an app’s code
runs in isolation from other apps.
◦ Every app runs in its own Linux process.
◦ Android starts the process when a app is launched, then shuts down
the process when it is no longer needed or when the system must
recover memory for other applications.
◦ Since Android 5.0 Lollipop system, the Dalvik VM has been officially
replaced by a new runtime called ART (Android RunTime).
12 / 33
Framework (I)
• activities: An activity is the key execution component. You need
at least one activity in an app that deals with the User Interface
(UI). An activity is implemented as a subclass of Activity.
• fragments: Fragments are relatively new to Android but very
important in programming the UI. They are mini-activities. A
fragment is implemented as a subclass of Fragment.
• intents: An Intent is a messaging object you can use to request an
action from another app component. Although intents facilitate
communication between components in several ways, there are
three fundamental use-cases:
◦ To start an activity
◦ To start a service
◦ To deliver a broadcast
13 / 33
Framework (II)
• services: Typically services are long running programs that do not
need to interact with the UI. A service is implemented as a
subclass of Service.
• content providers: Apps could share data. Content providers
manage access to a structured set of data. A content provider is
implemented as a subclass of ContentProvider.
• broadcast receivers: A Broadcast receiver allows you to register
for system or application events. All registered receivers for an
event are notified by the Android runtime once this event happens.
A broadcast receiver is implemented as a subclass of
BroadcastReceiver and each broadcast is delivered as an
Intent object.
14 / 33
App programming model
• Model-View-Controller (MVC)
15 / 33
Android Studio
16 / 33
Overview
• Android Studio 11 is the official IDE for Android apps development.
• It includes everything required for developing Android apps:
◦ Android SDK Tools
◦ Android Platform-tools
◦ Android platform versions
◦ Android system images (for the emulator)
• It is based on IntelliJ IDEA and offers 12
◦ Flexible Gradle-based build system
◦ Build variants and multiple apk file generation
◦ Code templates to help you build common app features
◦ ...
11
developer.android.com/sdk/index.html
12
developer.android.com/tools/studio/index.html
17 / 33
Setting up the development environment
• Get the Android Studio from
https://developer.android.com/sdk/index.html
• Setting Up Java
• Install Android Studio
• SDK Manager
◦ Get SDK tools
◦ Get the support library for additional APIs
◦ Get Google Play services for even more APIs
◦ Install the packages
• Creating an AVD
18 / 33
IDE - General view
19 / 33
IDE - Code editor
20 / 33
IDE - Logcat
21 / 33
IDE - Toolbar and Project view
• Toolbar
22 / 33
MVC
• Models:
◦ Shared Preferences
◦ SQLite Databases
◦ Network Connection
◦ Internal and External Storage
◦ Syncing to the Cloud
• Views
◦ XML files
• Controllers
◦ Java files
23 / 33
Class R
• All resource IDs are defined in your project’s R class, which the
aapt tool automatically generates.
• R class contains resource IDs for all the resources in your res/
directory.
• For each type of resource, there is an R subclass (for example,
R.layout for all layout resources), and for each resource of that
type, there is a static integer (for example,
R.layout.activity main). This integer is the resource ID that
you can use to retrieve your resource.
24 / 33
Android Manifest XML
• Every application must have a manifest.xml file in its root
directory.
• The manifest file presents essential information about app to the
Android system:
◦ Java package name for the application: the package name serves as a
unique identifier for the application.
◦ The components of the application: the activities, services, broadcast
receivers, and content providers.
◦ Permissions the application.
25 / 33
Practice
26 / 33
First App
• How to create an
Android Studio project
• Running on emulator
• Running on a real Device
27 / 33
Building a Simple User Interface Android App (I)
• Linear Layout
28 / 33
Building a Simple User Interface Android App (II)
• Supporting Different Languages
29 / 33
Building a Simple User Interface Android App (III)
• Supporting Different Screens
30 / 33
List view based app (I)
• List View
31 / 33
List view based app (II)
• Option menu
32 / 33
List view based app (III)
• Context menu
33 / 33