Android intro lecture
Download
Report
Transcript Android intro lecture
ANDROID
L. Grewe
Components
Java Standard Development Kit (JDK) (download)
http://www.oracle.com... (latest version)
AndroidStudio
Android SDK
What is Android
Android is not an operating system
Android is build on top of Linux Kernel
Android is not equivalent to Linux Kernel
Android is an open source
Android devices sales largest worldwide
Android and Java
•
•
•
Android does not use the standard JVM
Android own its own JVM (Dalvik)
Android Dalvik vs standard JVM
o register-based vs stack-based
o more efficient and compact implementation
o different set of java libraries than standard java libraries
Android and Java
cannot run standard Java bytecode on Android.
Android provides a tool "dx" which allows to convert Java Class
files into "dex" (Dalvik Executable) files.
o Android applications are packed into an .apk (Android Package)
file by the program "aapt" (Android Asset Packaging Tool)
o To simplify development Google provides the Android
Development Tools (ADT) with AndroidStudio. The ADT
performs automatically the conversion from class to dex files
and creates the apk during deployment.
o
o
Android FrameWork Stack
Android Linux Kernel
•
•
•
•
•
Hardware abstraction layer
Memory Management
Process Management
Networking
...
Android Native Libraries
•
•
•
•
•
•
•
Bionic
Surface Manager
2D and 3D grahics (OpenGL)
Media codecs
SQLite
WebKit
...
Android Framework
•
•
•
•
•
•
ActivityManager
Content providers
Resource manager
Location Manager
Notification Manager
...
Android Application
•
Android applications
o google maps
o facebook
o twitter
o ...
AndroidSDK
•
•
•
•
Tools
Docs
Platforms
o Android XX
Data
Skins
Images
Samples
Add-ons
o Google API
Android Process and Thread
•
Linux process per application
•
•
•
Runs under its own userid which is generated automatically by Android
system during deployment
Hence application isolated from other applications
One thread per process
o UI Thread
o manage Looper message
Android Application Components: Android
application =collection of loosly coupled components
•
•
•
•
•
Activity (and fragments)
Views
Service
Intents and Broadcast receiver (Intents reciever)
Content provider
Activity
presentation layer of an Android application, e.g. a screen
which the user sees.
An Android application can have several activities and it can
be switched between them during runtime of the application.
Newer introduction of fragments –like mini-activies grouped
together to create an activity
Activity
•
•
•
•
The building block of the user interface.
The Android analogue for the window or
dialog in a desktop application.
a single, focused thing that the user can do
takes care of creating a window for user
presentation to the user
o full-screen windows
o floating windows
o embedding inside of another activity
Lifecycle events will invoke the methods of Activity:
o void onCreate(Bundle savedInstanceState)
o void onStart()
o void onRestart()
o void onResume()
o void onPause()
o void onStop()
o void onDestroy()
Android Activity LifeCycle
Views
The User interface of an Activities is build with
widgets classes which inherent from
"android.view.View".
The layout of the views is managed by
"android.view.ViewGroups".
Services
perform background tasks without providing
an UI.
Usefull
when your app must communicate with backend
systems and not make your user wait for it to finish
Useful when you app has to do a lot of long calculations
and don’t want your user to wail
They can notify the user via the notification
framework in Android.
An example --- Pandora App –a music app
that can run in background and still play music
Service
•
•
•
•
•
•
•
to perform a longer-running operation while not interacting with
the user
can be started and stopped
doesn't have UI
run by activities
implicit Service (binding service)
explicit Service (start service)
lifecycle
o void onCreate()
o void onStart(Intent intent)
o void onDestroy()
Examples:
checking for updates to an RSS feed
playing back music even if the controlling activity is no longer operating.
Content Provider
•
store and retrieve data and make it accessible to all applications
•
to share data across applications
•
Android contains a SQLite DB which can serve as data provider
•
You can use pre-existing content-providers or you could create an
app that itself is a content provider for other applications to use.
•
Think about how some apps use your contact list ---this contact list
is a content provider that is built-in/existing already for you to use
in your application.
Intents
•
•
•
an abstract description of an operation to be performed
o action
o data
Explicit Intents (specified a component)
Implicit Intents
This may be a new idea for you --- it is a
asynchronous way of telling the Android
System you want to do something
We will learn more later about what this
means
Intents
Intents are system (asynchronous) messages, running around the inside of the device,
notifying applications of various events,
hardware state changes (e.g., an SD card was inserted),
incoming data (e.g., an SMS message arrived),
application events (e.g., your activity was launched from the device's main menu).
are asynchronous messages which allow the application to request functionality
from other services or activities. An application can call directly a service or
activity (explicit intent) or ask the Android system for registered services and
applications for an intent (implicit intents). For example the application could ask
via an intent for a contact application. Application register themself to an intent
via an IntentFilter. Intents are a powerful concept as they allow to create loosely
coupled applications.
Intents – Explicit, Implicit
An application can call directly a service or
activity (explicit intent)
An application can ask the Android system for
registered services and applications for an
intent (implicit intents).
Intents - Example
the application could ask via an intent for a
contact application.
Application register themself to an intent via
an IntentFilter.
Intents are a powerful concept as they allow to
create loosely coupled applications.
How to create Intents
You can receive and respond to intents by
intent
filters specification
intent/broadcast receivers
You can create your own intents to
launch
other activities,
let you know when specific situations arise (e.g.,
raise an intent when the user gets within 100
meters of a specified location)
Android Broadcast Receiver (Intents
receiver)
receive intents sent by sendBroadcast()
two type of broadcasts
o Normal broadcast
o Ordered broadcast
•
•
o
An application can register as a broadcast receiver for certain
events and can be started if such an event occurs.
future
We will learn more about what all of these main
components of an Android Application are slowly --so you will understand through the creation of apps
themselves.