Download To program Android - Activities, Services, Intents and DDMS

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
To program Android
Activities, Services, Intents and DDMS
Miguel Molina
Certec, Division of Rehabilitation Engineering Research
Department of Design Sciences
Faculty of Engineering
Lund University
2011-10-27
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Outline
1
Introduction
Android OS
Android SDK
2
An Android application
Activities, Services and Intents
The Lifecycle of Activities and Services
3
Debugging tools
DDMS
4
Haptimap Toolkit Introduction
The HaptiMap Toolkit
Some Android HCI Modules
5
DEMO
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
What is Android
What is Android? Really?
An Open Platform for Mobile Development
It is NOT a mobile phone
A package of preinstalled applications
A software development kit used to create applications
Builds on a Linux Kernel. Not a Linux OS
A full set of std Linux utilities not included
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
Why Android?
Open Source
Free mobile OS
You might develop from different platforms (Windows,
Linux, Mac)
You are already familiar with Java
Expected to account for 49% of the smartphone market by
2012 (according to Gartner)
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
System-Architecture
How does it look like?
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
The Android Software Stack
Linux Kernel Provides the abstraction layer between
hardware and the above layers
Native Libraries C/C++ build function libraries and native
servers. Hardware Abstraction Libraries: GPS, Audio,
Camera...
Android Run Time Makes the phone to an Android and
not a mobile Linux implementation
Dalvik Virtual Machine is Android’s virtual machine that
runs optimized Dalvik bytecode
Supports multiple virtual machine processes per device
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
Core Libraries: Core API for Java Language
Familiar development platform: Data structures, Utilities,
File access, etc..
Application Framework Provides the classes used to
create Android applications. Hardware services are
accessed through local Manager objects:
LocationManager mLocationManager =
(LocationManager)
getSystemService(LOCATION_SERVICE);
Application Layer All applications (native and 3rd party)
are build on this layer
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
Advantages using the Linux Kernel
Each Android application runs in its own virtual machine
Some core functions the kernel handles
Low-level memory management
Power Management with more aggressive policy
Application permissions and security model
Wi-Fi, audio, Flash memory, camera, display
Processes management and threading
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Android OS
Android SDK
Android SDK Features
Some of the features available on the Android SDK
APIs for location-based services, such as GPS
Multimedia hardware control such as playback, recording,
camera, etc.
APIs for sensors, such as accelerometer and compass
Integration of Map controls: Google Maps
Support for 2D and 3D graphics using OpenGL
SQLite Database
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
What is an Android Application?
An Android application is a collection of one or more tasks
(activities or services) plus a Linux process to contain
them
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
Multiple Applications
Android allows multiple applications to run concurrently
Applications can be interrupted and paused when events
occur
There can be only one active application visible to the user
at a time.
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
Activity vs Service
Activity Visible screen in the application
Service An activity without a user interface
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
What is an Activity?
A task or purpose
A user interface screen
It has its own life cycle
They extend the Context class
(you can get global info about your application)
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
The Lifecycle of an Activity
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
An activity’s lifecycle: Some @Override methods
onCreate() Creates the layout, data binding, contentview
onResume() An appropriated place to retrieve needed
instances to resources. Ex starting audio, video,
animations
onPause() Ex: stop audio, video or animations started at
onResume(). Could be the last thing to run before the
application is killed. A new foreground Activity will not start
until the onPause() returns.
onStop() and onDestroy() might not be executed at all.
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
Service
What is a Service?
A task that works in the background
(similar to a daemon)
It runs on the same process as the application it is part of.
It is not a Thread
No user direct interaction
Clients may bind to service
(Preferable than a Singleton pattern)
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Miguel Molina
Activities, Services and Intents
The Lifecycle of Activities and Services
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
A service’s lifecycle methods: Fewer than activity’s
onCreate(): initial setup
onStart(Intent intent): Start the active lifetime of a
service.
onDestroy(): releases all resources
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
Intents
The Message Mechanism
Intents?
An asynchronous message system that can be used to
pass data between activities.
Describes a specific action
What’s your intention?
Send mail, Open the browser, Start the camera, etc...
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
Intents Examples
Two examples when starting activities
with different purposes:
startActivity(new Intent(...));
startActivityForResult(new Intent(...));
Passing additional info to the intent
Intent intent = new Intent(...)
intent.putExtra("someString", "info")
someString follows the convention:
someString ="se.lth.certec.somestring"
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
Activities, Services and Intents
The Lifecycle of Activities and Services
Exchange Data between Activities
Use Intents:
intent.putExtra("someString", myClass);
You can send objects if they are Parcelable:
MyClass implements Parcelable {...}
The other activity:
getIntent().getParcelableExtra("someString");
Implement the Serializable MyClass implements
Serializable {...}
Use SharedPreferences
OR
Use a service as a Singleton pattern
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
DDMS
Debugging
The Dalvik Debug Monitor Service (DDMS) can be started from
Eclipse or from the the cmd/shell -> /Android directory/ddms.bat
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
DDMS
System.out.print / Log.*
Log messages on DDMS
Log.e(..., ...) Errors
Log.w(..., ...) Warnings
Log.i(..., ...) Information
Log.d(..., ...) Debugging
Log.v(..., ...) Verbose
Log.wtf(..., ...) What a Terrible Failure (Since 2.2)
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
What is HaptiMap Toolkit
It offers FIVE unique features and advantages
Access to Geographic Data in Vector format
Infrastructure for Acquiring Geographic Data from Multiple
Sources
Dynamic Contextualised Map Rendering
Cross platform API for mobile and desktop platforms
Pluggable HCI modules for specific platforms
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
Toolkit Architecture
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
Haptic Guide HCI
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
Audio Guide HCI
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
Speech Guide HCI
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
Scan Orientation HCI
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
The HaptiMap Toolkit
Some Android HCI Modules
Sound Bubbles HCI
Miguel Molina
To program Android
Introduction
An Android application
Debugging tools
Haptimap Toolkit Introduction
DEMO
DEMO
Miguel Molina
To program Android