SlideShare a Scribd company logo
Jumpstart to Android
App development

Lars Vogel
http://www.vogella.de
Twitter: @vogella
What is Android?

Fundamentals

Constructs of Android

Live Coding

Q&A
About me – Lars Vogel

Independent Eclipse and Android consultant,
trainer and book author

Eclipse committer

Maintains http://www.vogella.de Java, Eclipse
and Android related Tutorials with more then a
million visitors per month.
More Android Sessions:


Wednesday, 11.10 -
12.00 - So whats so cool about Android 4.x

Thuersday – Friday – Full day Android training
Android Experience?
What is
Android?
Android from 10 000 feet
- Open Source
- Full stack based on Linux
- Java programming interface
- Project is lead by Google
- Tooling available for Eclipse (and other IDE's)
Android Jumpstart Jfokus
On Android you develop in Java




(There is also the NDK which allows development in C / C++...)
Overview of the API Capabilities


 Rich UI components

 Threads and Background Processing

 Full network stack (Http, JSON)

 Database available

 Images

 Access to the hardware (GPS, Camera,
 Phone)

 and much more............
Its like
programming for
hardware which is
10 years old
… with insame
performance
requirements
On Android you develop in Java


Really?
Android Programming




 You use the Java
 programming language
 but Android does not run
 Java Bytecode
Dalvik

Run Dalvik Executable Code (.dex)
Tool dx converts Java Bytecode into .dex

•   Register based VM vrs. stack based as the JVM
•   .dex Files contain more then one class
•   Approx. 50 % of the size of a class file
•   op codes are two bytes instead of one in the JVM
•   As of Android 2.2 Dalvik JIT compiler
•   Primary engineer: Dan Bornstein
Developer
Toolchain
Android Development Tools (ADT)
for Eclipse



Eclipse based tooling
• Provide the emulator
• Wizard for creating new project
• Additional Tooling, e.g views
Emulator

           QEMU-based ARM emulator runs
           same image as a device

           Use same toolchain to work with
           device or emulator

           Inital startup is
           slooooowwwwww.....
Demo
AndroidManifest.xml

• General configuration files for
  your application
• Contains all component
  definitions of your appication
Resources from /res are
automatically „indexed“
ADT maintains a
reference to all
resources in the R.java
Main Android programming
       constructs
      Activity


          Views

             Intents

                 Broadcast Receiver

                  Services

                       ContentProvider
Context
Context
Global information about an application environment.

Allows access to application-specific resources and classes

Support application-level operations such as launching
activities, broadcasting and receiving intents, etc.

Basically all Android classes need a context

Activity extends Context
Demo
Activities project
    Your first
Activity
Extends Context

An activity is a single, focused
thing that the user can do.

Kind of a screen but not entirely...
View vrs ViewGroup


android.viewView: UI Widget
 - Button
 - TextView
 - EditText
Layouts
android.view.ViewGroup
 - Layout
 - extends View
• Layouts are typically defined via XML
  files (resources)
• You can assign properties to the
  layout elements to influence their
  behavior.
Demo – Hello JFokus
Andoid is
allowed to kill
your app to
save memory.
Life Cyle of an Activity



void onCreate(Bundle savedInstanceState)
void onStart()
void onRestart()
void onResume()
void onPause()
void onStop()
void onDestroy()
States of an Activity
• Active/ Running – Visible and interacts with user
• Paused – still visible but partically obscured (other
  transparant activity, dialog or the phone screen),
  instance is running but might be killed by the
  system
• Stopped – completely obscured, e.g. User presses
  the home screen button, instance is running but
  might be killed by the system
• Killed – if stopped or paused, system might calling
  finish or by killing it
Android Jumpstart Jfokus
To test flip your
     device
Def
    inin
        gA
          ctiv
               itie
                    s
Calling Activities


Calling Activities
creates a stack ->
Back button goes
back to the
previous activity


-> Think of it as a
stack of cards
Defining Activities
• Create a class which extends
  „Activitiy“
• Create an entry in
  „AndroidManifest.xml“ for the activity.
• <activity
  android:name=“MyNewActivity“></a
  ctivity>
I had only the
best intents....
Intents


Message passing mechanism to start
Activities, Services or to trigger
(system) events.

Allow modular architecture

Can contain data (extra)
Intents



 • Explicit: Asking someone to do something
 • Implicit: Asking the system who can do something


                   Intent
Demo Intents
Implicit Intents

• new Intent(Intent.ACTION_VIEW,
  Uri.parse("http://www.vogella.de"));
• new Intent(Intent.ACTION_CALL, Uri.parse("tel:
  (+49)12345789"));
• new Intent(Intent.ACTION_VIEW,
  Uri.parse("geo:50.123,7.1434?z=19"));
• new
  Intent("android.media.action.IMAGE_CAPTURE");
Gettings results
Intent intent = new
Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);

public void onActivityResult(int requestCode, int
resultCode, Intent data) {
 if (resultCode == Activity.RESULT_OK && requestCode
== 0) {
   String result = data.toURI();
   Toast.makeText(this, result, Toast.LENGTH_LONG);
 }
}
XML
Drawables
XML Drawables
• XML Resources
• Can be used to define transitions,
  shapes or state
  A drawable resource is something
  that can be drawn to the screen
Services and receiver
Services

Allow real multitasking and background processing

De-coupled from the Activity life-cyle
Services

Service runs in the background without interacting with the user.

Android provides a multitude of system services

•   NotificationService
•   VibratorService
•   LocationService
•   AlarmService
•   ....

Access via context.getSystemService(Context.CONST);

You can define your own service for things that should run in the
background
Notification
 Manager
  Demo
Services

Service runs in the background without interacting with the user.

Android provides a multitude of system services

•   NotificationService
•   VibratorService
•   LocationService
•   AlarmService
•   ....

Access via context.getSystemService(Context.CONST);

You can define your own service for things that should run in the
background
Broadcast Receiver – Listen to events


 Example:
 BATTERY_LOW,
 ACTION_BOOT_COMPLETED
 android.intent.action.PHONE_STATE


 Defined statically in manifest or temporary
 via code

 Broadcast Receiver only works within the
 onReceive() method

 C2DM
Own Service
• Extend Service or IntentService
• start with startService(Intent) or
  bindService(Intent).
• onStartCommand is called in the service
• bindService gets a ServiceConnection as
  parameter which receives a Binder object
  which can be used to communicate with the
  service
How to start a service


 Broadcast Receiver –
 Event: BOOT_COMPLETED

 Or

 ACTION_EXTERNAL_APPLICATIONS_A
 VAILABLE

 startService in the onReceiveMethod()

 Timer Service
 Start BroadcastReceiver which starts the
 service
Demo
    alarm
receiver.phone
Security
Each apps gets into own Linux user
and runs in its own process
Android Application requires
explicit permissions, e.g. for
• DB access
•   Phone access
•   Contacts
•   Internet
•   System messages
Background Processing
Be fast!

Avoid ApplicationNotResponding
Error
Use Threads (not the UI one)
• Long running stuff should run in the
  background
• Thread cannot modify the UI
• Synch with the UI thread

    runOnUiThread(new Runnable)
Handler and AsyncTask
• Handler runs in the UI thread
• Allows to send Message object and or
  to send Runnable to it
      handler.sendMessage(msg)
     handler.post(runnable)

• AsyncTask for more complex work
AsyncTask
• To use it subclass it

AsyncTask <TypeOfVarArgParams , ProgressValue ,
ResultValue>

doInBackground() – Do the work

onPostExecute() – Update the UI
Saving the thread
• If a thread runs in your Activity you
  want to save it.
Lifecycle - Thread
• If Activity is destroyed the Threads should be
  preserved.
• Close down Dialogs in the onDestroy() method
• One object can be saved via
  onRetainConConfigurationInstance()
• Access via getLastNonConfigurationInstance()
• Only use static inner classes in your Threads
  otherwise you create a memory leakage.
Option Menus and
       Action Bar
Option Menu & Action Bar
• Option Menu displays if „Menu“
  button is pressed
• You can decided if the entries are
  displayed in the Action Bar or in a
  menu
• Use „ifRoom“ flag if possible.
Option Menu & Action Bar
• Option Menu displays if „Menu“
  button is pressed
• You can decided if the entries are
  displayed in the Action Bar or in a
  menu
• Use „ifRoom“ flag if possible.
Preferences
Read and Write Preferences
• Key – Value pairs

• PreferenceManager.getDefaultShared
  Preferences(this);
 – To read: getString(key), get...
 – To change use edit(), putType(key, value),
   commit()
• To maintain use PreferenceActivity
PreferenceActivity
• Create resource file (preference)
• New Activity which extends
  PreferenceActivity
• To add preferences:
 – addPreferencesFromResource(R.xml.prefer
   ences);
• Saving and edits will be handled
  automatically by the
  PreferenceActivity
ListView
ListView


Can be used to display a list of items

Gets his data from an adapter
Adapter
                       Data for ListView
                       defined by Adapter




View per row defined
by Adapter
ListActivity


ListActivity has already a predefined ListView with the id @android:id/list
which will be used automatically.

Provides nice method hooks for typical operations on lists

If you define your own layout this layout must contain a ListView with the
ID:

@+android:id/list
What if the layout should
     not be static?
Define your own Adapter
Reuse existing rows


If convertView is not null -> reuse it

Saves memory and CPU power (approx. 150 % faster according to
Google IO)

Holder Pattern saves 25%
Views and Touch
There is more....
I have
feelings

           Camera API
           Motion Detection
           Location API (GIS)
           Heat Sensor
           Accelerator
Example Camera API
I can talk and
     hear


Internet (java.net, Apache HttpClient, JSON...)
Bluetooth
Email
SMS
VoIP (SIP (Session Initiation Protocol))
Other Capabilities

Push to device

Interactive Widgets on the homescreen

Live Wallpapers (as background)

Animations and Styling

Simple List handling

(Multi-) Touch

NFC

Canvas / OpenGL ES (Game programming....)

Native Rendering
Android 4.0
Whats so cool about Android 4.0?




• Come to my talk on Wednesday... ;-)
Summary
Android powerful and well-
 designed development
         platform

   Easy to get started

 Power to the developer
Android Jumpstart Jfokus
Android: Where to go
          from here:

Android Introduction Tutorial
   http://www.vogella.de/articles/Android/article.html

Or Google for „Android Development Tutorial“

Android SQLite and ContentProvider Book
http://www.amazon.com/dp/B006YUWEFE


More on Android
http://www.vogella.de/android.html
Thank you
For further questions:


Lars.Vogel@gmail.com
http://www.vogella.de
Twitter http://www.twitter.com/vogella
Google+ http://gplus.to/vogella
License &
           Acknowledgements
•   This work is licensed under the Creative Commons
    Attribution-Noncommercial-No Derivative Works 3.0
    Germany License




    – See http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en_US

More Related Content

Similar to Android Jumpstart Jfokus (20)

PDF
Androidoscon20080721 1216843094441821-9
Gustavo Fuentes Zurita
 
PDF
Androidoscon20080721 1216843094441821-9
Gustavo Fuentes Zurita
 
PPT
Introduction to Android Development
Can Elmas
 
PDF
Introduction to Android Development
Aly Abdelkareem
 
PPTX
Android101 - Intro and Basics
jromero1214
 
PDF
Android development first steps
christoforosnalmpantis
 
PPT
Android Training Ahmedabad , Android Course Ahmedabad, Android architecture
NicheTech Com. Solutions Pvt. Ltd.
 
PDF
Android application development
slidesuren
 
PDF
Getting Started with Android - OSSPAC 2009
sullis
 
PPT
Android Tutorial
Fun2Do Labs
 
PDF
Android Workshop_1
Purvik Rana
 
PDF
Marakana android-java developers
Marko Gargenta
 
PPTX
Android beginners David
Arun David Johnson R
 
PDF
Android Development
mclougm4
 
PPT
LA_FUNDAMENTALS OF Android_Unit I ONE.ppt
JeevaMCSEKIOT
 
PPTX
Seminar on android app development
AbhishekKumar4779
 
PDF
Android Bootcamp
ahkjsdcsadc
 
DOCX
Android Tutorial For Beginners Part-1
Amit Saxena
 
PPT
Introduction to android sessions new
Joe Jacob
 
PDF
Android tutorial
Abid Khan
 
Androidoscon20080721 1216843094441821-9
Gustavo Fuentes Zurita
 
Androidoscon20080721 1216843094441821-9
Gustavo Fuentes Zurita
 
Introduction to Android Development
Can Elmas
 
Introduction to Android Development
Aly Abdelkareem
 
Android101 - Intro and Basics
jromero1214
 
Android development first steps
christoforosnalmpantis
 
Android Training Ahmedabad , Android Course Ahmedabad, Android architecture
NicheTech Com. Solutions Pvt. Ltd.
 
Android application development
slidesuren
 
Getting Started with Android - OSSPAC 2009
sullis
 
Android Tutorial
Fun2Do Labs
 
Android Workshop_1
Purvik Rana
 
Marakana android-java developers
Marko Gargenta
 
Android beginners David
Arun David Johnson R
 
Android Development
mclougm4
 
LA_FUNDAMENTALS OF Android_Unit I ONE.ppt
JeevaMCSEKIOT
 
Seminar on android app development
AbhishekKumar4779
 
Android Bootcamp
ahkjsdcsadc
 
Android Tutorial For Beginners Part-1
Amit Saxena
 
Introduction to android sessions new
Joe Jacob
 
Android tutorial
Abid Khan
 

More from Lars Vogel (20)

PDF
Eclipse IDE and Platform news on Fosdem 2020
Lars Vogel
 
PDF
Eclipse platform news and how to contribute to the Eclipse Open Source project
Lars Vogel
 
PDF
Android design and Custom views
Lars Vogel
 
PDF
How to become an Eclipse committer in 20 minutes and fork the IDE
Lars Vogel
 
PDF
Building beautiful User Interface in Android
Lars Vogel
 
PDF
What is so cool about Android 4.0
Lars Vogel
 
PDF
What is so cool about Android 4.0?
Lars Vogel
 
PDF
Eclipse e4 - Google Eclipse Day
Lars Vogel
 
PPT
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Lars Vogel
 
PPTX
Android Overview (Karlsruhe VKSI)
Lars Vogel
 
PPTX
Android Introduction on Java Forum Stuttgart 11
Lars Vogel
 
PPT
Eclipse 2011 Hot Topics
Lars Vogel
 
PPT
Google App Engine for Java
Lars Vogel
 
PPTX
Android Cloud to Device Messaging with the Google App Engine
Lars Vogel
 
PDF
Google App Engine for Java
Lars Vogel
 
PPTX
Eclipse 4.0 - Dynamic Models
Lars Vogel
 
PDF
Eclipse 40 Labs- Eclipse Summit Europe 2010
Lars Vogel
 
PDF
Eclipse 40 - Eclipse Summit Europe 2010
Lars Vogel
 
PPTX
Android Programming made easy
Lars Vogel
 
PPTX
Eclipse 40 and Eclipse e4
Lars Vogel
 
Eclipse IDE and Platform news on Fosdem 2020
Lars Vogel
 
Eclipse platform news and how to contribute to the Eclipse Open Source project
Lars Vogel
 
Android design and Custom views
Lars Vogel
 
How to become an Eclipse committer in 20 minutes and fork the IDE
Lars Vogel
 
Building beautiful User Interface in Android
Lars Vogel
 
What is so cool about Android 4.0
Lars Vogel
 
What is so cool about Android 4.0?
Lars Vogel
 
Eclipse e4 - Google Eclipse Day
Lars Vogel
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Lars Vogel
 
Android Overview (Karlsruhe VKSI)
Lars Vogel
 
Android Introduction on Java Forum Stuttgart 11
Lars Vogel
 
Eclipse 2011 Hot Topics
Lars Vogel
 
Google App Engine for Java
Lars Vogel
 
Android Cloud to Device Messaging with the Google App Engine
Lars Vogel
 
Google App Engine for Java
Lars Vogel
 
Eclipse 4.0 - Dynamic Models
Lars Vogel
 
Eclipse 40 Labs- Eclipse Summit Europe 2010
Lars Vogel
 
Eclipse 40 - Eclipse Summit Europe 2010
Lars Vogel
 
Android Programming made easy
Lars Vogel
 
Eclipse 40 and Eclipse e4
Lars Vogel
 
Ad

Recently uploaded (20)

PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Ad

Android Jumpstart Jfokus

  • 1. Jumpstart to Android App development Lars Vogel http://www.vogella.de Twitter: @vogella
  • 2. What is Android? Fundamentals Constructs of Android Live Coding Q&A
  • 3. About me – Lars Vogel Independent Eclipse and Android consultant, trainer and book author Eclipse committer Maintains http://www.vogella.de Java, Eclipse and Android related Tutorials with more then a million visitors per month.
  • 4. More Android Sessions: Wednesday, 11.10 - 12.00 - So whats so cool about Android 4.x Thuersday – Friday – Full day Android training
  • 7. Android from 10 000 feet - Open Source - Full stack based on Linux - Java programming interface - Project is lead by Google - Tooling available for Eclipse (and other IDE's)
  • 9. On Android you develop in Java (There is also the NDK which allows development in C / C++...)
  • 10. Overview of the API Capabilities Rich UI components Threads and Background Processing Full network stack (Http, JSON) Database available Images Access to the hardware (GPS, Camera, Phone) and much more............
  • 11. Its like programming for hardware which is 10 years old
  • 13. On Android you develop in Java Really?
  • 14. Android Programming You use the Java programming language but Android does not run Java Bytecode
  • 15. Dalvik Run Dalvik Executable Code (.dex) Tool dx converts Java Bytecode into .dex • Register based VM vrs. stack based as the JVM • .dex Files contain more then one class • Approx. 50 % of the size of a class file • op codes are two bytes instead of one in the JVM • As of Android 2.2 Dalvik JIT compiler • Primary engineer: Dan Bornstein
  • 17. Android Development Tools (ADT) for Eclipse Eclipse based tooling • Provide the emulator • Wizard for creating new project • Additional Tooling, e.g views
  • 18. Emulator QEMU-based ARM emulator runs same image as a device Use same toolchain to work with device or emulator Inital startup is slooooowwwwww.....
  • 19. Demo
  • 20. AndroidManifest.xml • General configuration files for your application • Contains all component definitions of your appication
  • 21. Resources from /res are automatically „indexed“
  • 22. ADT maintains a reference to all resources in the R.java
  • 23. Main Android programming constructs Activity Views Intents Broadcast Receiver Services ContentProvider
  • 25. Context Global information about an application environment. Allows access to application-specific resources and classes Support application-level operations such as launching activities, broadcasting and receiving intents, etc. Basically all Android classes need a context Activity extends Context
  • 27. Activity Extends Context An activity is a single, focused thing that the user can do. Kind of a screen but not entirely...
  • 28. View vrs ViewGroup android.viewView: UI Widget - Button - TextView - EditText
  • 29. Layouts android.view.ViewGroup - Layout - extends View • Layouts are typically defined via XML files (resources) • You can assign properties to the layout elements to influence their behavior.
  • 30. Demo – Hello JFokus
  • 31. Andoid is allowed to kill your app to save memory.
  • 32. Life Cyle of an Activity void onCreate(Bundle savedInstanceState) void onStart() void onRestart() void onResume() void onPause() void onStop() void onDestroy()
  • 33. States of an Activity • Active/ Running – Visible and interacts with user • Paused – still visible but partically obscured (other transparant activity, dialog or the phone screen), instance is running but might be killed by the system • Stopped – completely obscured, e.g. User presses the home screen button, instance is running but might be killed by the system • Killed – if stopped or paused, system might calling finish or by killing it
  • 35. To test flip your device
  • 36. Def inin gA ctiv itie s
  • 37. Calling Activities Calling Activities creates a stack -> Back button goes back to the previous activity -> Think of it as a stack of cards
  • 38. Defining Activities • Create a class which extends „Activitiy“ • Create an entry in „AndroidManifest.xml“ for the activity. • <activity android:name=“MyNewActivity“></a ctivity>
  • 39. I had only the best intents....
  • 40. Intents Message passing mechanism to start Activities, Services or to trigger (system) events. Allow modular architecture Can contain data (extra)
  • 41. Intents • Explicit: Asking someone to do something • Implicit: Asking the system who can do something Intent
  • 43. Implicit Intents • new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.vogella.de")); • new Intent(Intent.ACTION_CALL, Uri.parse("tel: (+49)12345789")); • new Intent(Intent.ACTION_VIEW, Uri.parse("geo:50.123,7.1434?z=19")); • new Intent("android.media.action.IMAGE_CAPTURE");
  • 44. Gettings results Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 0); public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == 0) { String result = data.toURI(); Toast.makeText(this, result, Toast.LENGTH_LONG); } }
  • 46. XML Drawables • XML Resources • Can be used to define transitions, shapes or state A drawable resource is something that can be drawn to the screen
  • 48. Services Allow real multitasking and background processing De-coupled from the Activity life-cyle
  • 49. Services Service runs in the background without interacting with the user. Android provides a multitude of system services • NotificationService • VibratorService • LocationService • AlarmService • .... Access via context.getSystemService(Context.CONST); You can define your own service for things that should run in the background
  • 51. Services Service runs in the background without interacting with the user. Android provides a multitude of system services • NotificationService • VibratorService • LocationService • AlarmService • .... Access via context.getSystemService(Context.CONST); You can define your own service for things that should run in the background
  • 52. Broadcast Receiver – Listen to events Example: BATTERY_LOW, ACTION_BOOT_COMPLETED android.intent.action.PHONE_STATE Defined statically in manifest or temporary via code Broadcast Receiver only works within the onReceive() method C2DM
  • 53. Own Service • Extend Service or IntentService • start with startService(Intent) or bindService(Intent). • onStartCommand is called in the service • bindService gets a ServiceConnection as parameter which receives a Binder object which can be used to communicate with the service
  • 54. How to start a service Broadcast Receiver – Event: BOOT_COMPLETED Or ACTION_EXTERNAL_APPLICATIONS_A VAILABLE startService in the onReceiveMethod() Timer Service Start BroadcastReceiver which starts the service
  • 55. Demo alarm receiver.phone
  • 57. Each apps gets into own Linux user and runs in its own process
  • 58. Android Application requires explicit permissions, e.g. for • DB access • Phone access • Contacts • Internet • System messages
  • 61. Use Threads (not the UI one) • Long running stuff should run in the background • Thread cannot modify the UI • Synch with the UI thread runOnUiThread(new Runnable)
  • 62. Handler and AsyncTask • Handler runs in the UI thread • Allows to send Message object and or to send Runnable to it handler.sendMessage(msg) handler.post(runnable) • AsyncTask for more complex work
  • 63. AsyncTask • To use it subclass it AsyncTask <TypeOfVarArgParams , ProgressValue , ResultValue> doInBackground() – Do the work onPostExecute() – Update the UI
  • 64. Saving the thread • If a thread runs in your Activity you want to save it.
  • 65. Lifecycle - Thread • If Activity is destroyed the Threads should be preserved. • Close down Dialogs in the onDestroy() method • One object can be saved via onRetainConConfigurationInstance() • Access via getLastNonConfigurationInstance() • Only use static inner classes in your Threads otherwise you create a memory leakage.
  • 66. Option Menus and Action Bar
  • 67. Option Menu & Action Bar • Option Menu displays if „Menu“ button is pressed • You can decided if the entries are displayed in the Action Bar or in a menu • Use „ifRoom“ flag if possible.
  • 68. Option Menu & Action Bar • Option Menu displays if „Menu“ button is pressed • You can decided if the entries are displayed in the Action Bar or in a menu • Use „ifRoom“ flag if possible.
  • 70. Read and Write Preferences • Key – Value pairs • PreferenceManager.getDefaultShared Preferences(this); – To read: getString(key), get... – To change use edit(), putType(key, value), commit() • To maintain use PreferenceActivity
  • 71. PreferenceActivity • Create resource file (preference) • New Activity which extends PreferenceActivity • To add preferences: – addPreferencesFromResource(R.xml.prefer ences); • Saving and edits will be handled automatically by the PreferenceActivity
  • 73. ListView Can be used to display a list of items Gets his data from an adapter
  • 74. Adapter Data for ListView defined by Adapter View per row defined by Adapter
  • 75. ListActivity ListActivity has already a predefined ListView with the id @android:id/list which will be used automatically. Provides nice method hooks for typical operations on lists If you define your own layout this layout must contain a ListView with the ID: @+android:id/list
  • 76. What if the layout should not be static?
  • 77. Define your own Adapter
  • 78. Reuse existing rows If convertView is not null -> reuse it Saves memory and CPU power (approx. 150 % faster according to Google IO) Holder Pattern saves 25%
  • 81. I have feelings Camera API Motion Detection Location API (GIS) Heat Sensor Accelerator
  • 83. I can talk and hear Internet (java.net, Apache HttpClient, JSON...) Bluetooth Email SMS VoIP (SIP (Session Initiation Protocol))
  • 84. Other Capabilities Push to device Interactive Widgets on the homescreen Live Wallpapers (as background) Animations and Styling Simple List handling (Multi-) Touch NFC Canvas / OpenGL ES (Game programming....) Native Rendering
  • 86. Whats so cool about Android 4.0? • Come to my talk on Wednesday... ;-)
  • 87. Summary Android powerful and well- designed development platform Easy to get started Power to the developer
  • 89. Android: Where to go from here: Android Introduction Tutorial http://www.vogella.de/articles/Android/article.html Or Google for „Android Development Tutorial“ Android SQLite and ContentProvider Book http://www.amazon.com/dp/B006YUWEFE More on Android http://www.vogella.de/android.html
  • 90. Thank you For further questions: [email protected] http://www.vogella.de Twitter http://www.twitter.com/vogella Google+ http://gplus.to/vogella
  • 91. License & Acknowledgements • This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License – See http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en_US