IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
To program AndroidActivities, Services, Intents and DDMS
Miguel Molina
Certec, Division of Rehabilitation Engineering ResearchDepartment of Design Sciences
Faculty of EngineeringLund University
2011-10-27
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Outline
1 IntroductionAndroid OSAndroid SDK
2 An Android applicationActivities, Services and IntentsThe Lifecycle of Activities and Services
3 Debugging toolsDDMS
4 Haptimap Toolkit IntroductionThe HaptiMap ToolkitSome Android HCI Modules
5 DEMO
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
What is Android
What is Android? Really?
An Open Platform for Mobile DevelopmentIt is NOT a mobile phoneA package of preinstalled applicationsA software development kit used to create applicationsBuilds on a Linux Kernel. Not a Linux OSA full set of std Linux utilities not included
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
Why Android?
Open SourceFree mobile OSYou might develop from different platforms (Windows,Linux, Mac)You are already familiar with JavaExpected to account for 49% of the smartphone market by2012 (according to Gartner)
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
System-Architecture
How does it look like?
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
The Android Software Stack
Linux Kernel Provides the abstraction layer betweenhardware and the above layersNative Libraries C/C++ build function libraries and nativeservers. Hardware Abstraction Libraries: GPS, Audio,Camera...Android Run Time Makes the phone to an Android andnot a mobile Linux implementation
Dalvik Virtual Machine is Android’s virtual machine thatruns optimized Dalvik bytecodeSupports multiple virtual machine processes per device
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
Core Libraries: Core API for Java LanguageFamiliar development platform: Data structures, Utilities,File access, etc..
Application Framework Provides the classes used tocreate Android applications. Hardware services areaccessed 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
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
Advantages using the Linux Kernel
Each Android application runs in its own virtual machineSome core functions the kernel handles
Low-level memory managementPower Management with more aggressive policyApplication permissions and security modelWi-Fi, audio, Flash memory, camera, displayProcesses management and threading
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Android OSAndroid SDK
Android SDK Features
Some of the features available on the Android SDKAPIs for location-based services, such as GPSMultimedia hardware control such as playback, recording,camera, etc.APIs for sensors, such as accelerometer and compassIntegration of Map controls: Google MapsSupport for 2D and 3D graphics using OpenGLSQLite Database
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe 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 containthem
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
Multiple Applications
Android allows multiple applications to run concurrentlyApplications can be interrupted and paused when eventsoccurThere can be only one active application visible to the userat a time.
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
Activity vs Service
Activity Visible screen in the applicationService An activity without a user interface
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
What is an Activity?
A task or purposeA user interface screenIt has its own life cycleThey extend the Context class(you can get global info about your application)
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
The Lifecycle of an Activity
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
An activity’s lifecycle: Some @Override methodsonCreate() Creates the layout, data binding, contentviewonResume() An appropriated place to retrieve neededinstances to resources. Ex starting audio, video,animationsonPause() Ex: stop audio, video or animations started atonResume(). Could be the last thing to run before theapplication is killed. A new foreground Activity will not startuntil the onPause() returns.onStop() and onDestroy() might not be executed at all.
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe 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 ThreadNo user direct interactionClients may bind to service(Preferable than a Singleton pattern)
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
A service’s lifecycle methods: Fewer than activity’sonCreate(): initial setuponStart(Intent intent): Start the active lifetime of aservice.onDestroy(): releases all resources
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
IntentsThe Message Mechanism
Intents?
An asynchronous message system that can be used topass data between activities.Describes a specific actionWhat’s your intention?Send mail, Open the browser, Start the camera, etc...
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe Lifecycle of Activities and Services
Intents Examples
Two examples when starting activitieswith 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
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
Activities, Services and IntentsThe 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 implementsSerializable {...}Use SharedPreferencesORUse a service as a Singleton pattern
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
DDMS
Debugging
The Dalvik Debug Monitor Service (DDMS) can be started fromEclipse or from the the cmd/shell -> /Android directory/ddms.bat
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
DDMS
System.out.print / Log.*
Log messages on DDMSLog.e(..., ...) ErrorsLog.w(..., ...) WarningsLog.i(..., ...) InformationLog.d(..., ...) DebuggingLog.v(..., ...) VerboseLog.wtf(..., ...) What a Terrible Failure (Since 2.2)
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
What is HaptiMap Toolkit
It offers FIVE unique features and advantages
Access to Geographic Data in Vector formatInfrastructure for Acquiring Geographic Data from MultipleSourcesDynamic Contextualised Map RenderingCross platform API for mobile and desktop platformsPluggable HCI modules for specific platforms
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
Toolkit Architecture
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
Haptic Guide HCI
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
Audio Guide HCI
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
Speech Guide HCI
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
Scan Orientation HCI
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
The HaptiMap ToolkitSome Android HCI Modules
Sound Bubbles HCI
Miguel Molina To program Android
IntroductionAn Android application
Debugging toolsHaptimap Toolkit Introduction
DEMO
DEMO
Miguel Molina To program Android