Android Development      - the basics    Tomáš Kypta      @TomasKypta
Outline●   Android platform●   Android ecosystem●   Android SDK and development tools●   Hello World●   building blocks & ...
Android platform●   Linux-based operating system●   open-source●   originally phone OS●   tablet (since Honeycomb, Android...
History●   2003, Android inc.●   2005 acquired by Google●   Sep 2008 first Android phone – T-Mobile G1●   since then rapid...
Android ecosystem●   the worlds most popular mobile platform●   1.3M new devices activated every day●   of that 70k tablet...
Google Play●   ~ 675 000 apps in the market●   total downloads > 25 billion●   ~ 70% free apps●   ads, in-app billing●   s...
Android problems●   fragmentation●   manufacturer/carrier enhancements●   updates & support●   openness – low quality apps...
Permissions●   users accept when installing or updating the    app●   apps can be installed directly from .apk file
Sources●   developer.android.com●   android-developers.blogspot.com●   source.android.com●   stackoverflow.com●   youtube....
Development●   programming in “Java”●   native apps possible (C++)●   development tools platform friendly●   Windows, Linu...
Android SDK●   android – Android SDK and AVD Manager●   adb – Android Debug Bridge●   ddms – Dalvik Debug Monitor●   emula...
Libraries●   compatibility libraries        – v4 – backports lots of newer            functionality to android 1.6+●   lic...
Android internals
Hello World
Build
Android Building Blocks●   Activity●   Service●   Content provider●   Broadcast receiver●   AndroidManifest.xml
Activity●   screen with user interface●   the only visual component●   example – an email app can contain:        –   list...
Service●   has no UI●   long-running tasks●   examples:       –   music playback service       –   download service       ...
Content Provider●   manages and shares application data●   data storage doesnt matter – database, web,    filesystem●   ap...
Broadcast Receiver●   responds to broadcasts●   broadcasts are system wide●   can be registered statically or dynamically●...
AndroidManifest.xml●   defines what parts the app have●   defines which endpoints are exposed●   minimum/maximum API level...
Intent●   asynchronous message●   binds components together (all of them    except ContentProvider)●   starting activities...
Activity●   a subclass of android.app.Activity●   app usually has many activities●   activities managed in activity stack ...
Activity Lifecycle●   activity can be in different states during its    lifecycle:        –   foreground        –   visibl...
Activity callbacks●   onCreate() - activity created●   onStart() - becoming visible to the user●   onResume() - gains user...
Intent & Activity●   starting activity explicitly●   starting activity implicitly●   starting activity for result
Configuration changes●   when configuration changes activities are    destroyed and recreated by default        –   place ...
User Interface●   defined by hierarchy of views●   layouts = containers       –   LinearLayout       –   RelativeLayout   ...
List Widgets●   displays a list of items (some view)        –   ListView, Spinner, GridView, Gallery●   use adapter to bin...
Resources●   drawables – bitmaps, 9-patch png, state-list,    layer list, shape drawable, ...●   layouts●   strings●   col...
Screen sizes and densities●   How to handle so many different devices?
Resource units●   dp/dip – density-independent pixel●   sp – scale-independent pixel
Resources●   generated file R.java●   resource ids●   makes resources accessible in the code●●   resources can be created ...
Resource qualifiers●   screen density – ldpi, mdpi, hdpi, xhdpi●   screen size – small, normal, large, xlarge●   screen or...
Android version fragmentation●   How to handle different API levels avialable    on devices?●   build target        –   pr...
Android version fragmentationif (Build.VERSION.SDK_INT <      Build.VERSION_CODES.GINGERBREAD) {         // only for andro...
Android version fragmentationprivate boolean functionalitySupported = false;static {           try {                   che...
Fragments●   a piece of application UI●   fragment != activity●   fragments used within activities●   since Android 3.0●  ...
Threads●   main thread = UI thread●   do not block the UI thread●   use worker threads for time consuming    operations●  ...
Menu●   Android pre 3.0 – menu hidden under menu    button●   Android 3.0+ has ActionBar:       –   items can be displayed...
Dialogs and Toasts●   Dialog – floating window screen       –   standard dialogs       –   custom dialogs       –   since ...
Notifications●   a message that can be displayed to the user    outside your normal UI●   displayed in notification area● ...
THE END
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012
Android development - the basics, MFF UK, 2012
Upcoming SlideShare
Loading in...5
×

Android development - the basics, MFF UK, 2012

1,408

Published on

Introductory lecture to Android development. Faculty of Mathematics and Physics in Prague, 2012.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,408
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android development - the basics, MFF UK, 2012

  1. 1. Android Development - the basics Tomáš Kypta @TomasKypta
  2. 2. Outline● Android platform● Android ecosystem● Android SDK and development tools● Hello World● building blocks & the manifest file● activities, widgets, intents● dialog, toasts, notifications● fragments
  3. 3. Android platform● Linux-based operating system● open-source● originally phone OS● tablet (since Honeycomb, Android 3.0)● Google TV● hundreds of devices
  4. 4. History● 2003, Android inc.● 2005 acquired by Google● Sep 2008 first Android phone – T-Mobile G1● since then rapid development of the platform● May 2010 Froyo● Feb 2011 Honeycomb● Oct 2011 Ice Cream Sandwich● Jul 2012 Jelly Bean
  5. 5. Android ecosystem● the worlds most popular mobile platform● 1.3M new devices activated every day● of that 70k tablets● total number of devices ~ 500 million● play.google.com (market.android.com)● other store – Amazon Appstore for Android, ...
  6. 6. Google Play● ~ 675 000 apps in the market● total downloads > 25 billion● ~ 70% free apps● ads, in-app billing● selling – 15 min return period● buy – ČR, SR● sell – ČR● Google Play contains also music, books – not available in ČR, SR
  7. 7. Android problems● fragmentation● manufacturer/carrier enhancements● updates & support● openness – low quality apps in Google Play● malware - users
  8. 8. Permissions● users accept when installing or updating the app● apps can be installed directly from .apk file
  9. 9. Sources● developer.android.com● android-developers.blogspot.com● source.android.com● stackoverflow.com● youtube.com/androiddevelopers● svetandroida.cz
  10. 10. Development● programming in “Java”● native apps possible (C++)● development tools platform friendly● Windows, Linux, Mac OS X● IDE support – ADT plugin for Eclipse, Netbeans, IntelliJ IDEA, ...● you can freely develop on your device
  11. 11. Android SDK● android – Android SDK and AVD Manager● adb – Android Debug Bridge● ddms – Dalvik Debug Monitor● emulator● lint, hierarchyviewer, Traceview● ProGuard● docs, samples
  12. 12. Libraries● compatibility libraries – v4 – backports lots of newer functionality to android 1.6+● licensing, billing libraries● AdMob● Google Analytics, Flurry, Crittercism, ...● C2DM
  13. 13. Android internals
  14. 14. Hello World
  15. 15. Build
  16. 16. Android Building Blocks● Activity● Service● Content provider● Broadcast receiver● AndroidManifest.xml
  17. 17. Activity● screen with user interface● the only visual component● example – an email app can contain: – list of emails – email detail – email composition – preference screen – ...
  18. 18. Service● has no UI● long-running tasks● examples: – music playback service – download service – sync service
  19. 19. Content Provider● manages and shares application data● data storage doesnt matter – database, web, filesystem● apps can query and modify data through content provider● read/write permissions can be defined● examples: – all system databases – contacts – SMS
  20. 20. Broadcast Receiver● responds to broadcasts● broadcasts are system wide● can be registered statically or dynamically● system or custom messages● examples: – incoming SMS, incoming call – screen turned off – low baterry – removed SD card
  21. 21. AndroidManifest.xml● defines what parts the app have● defines which endpoints are exposed● minimum/maximum API level● permissions● declare hardware and software features● required configuration
  22. 22. Intent● asynchronous message● binds components together (all of them except ContentProvider)● starting activities● starting services and binding to services● sending broadcasts
  23. 23. Activity● a subclass of android.app.Activity● app usually has many activities● activities managed in activity stack – newly started activity is place on the top of the stack
  24. 24. Activity Lifecycle● activity can be in different states during its lifecycle: – foreground – visible – stopped – killed● when activity state changes a system callback is called
  25. 25. Activity callbacks● onCreate() - activity created● onStart() - becoming visible to the user● onResume() - gains user focus● onPause() - system resuming previous activity● onStop() - becoming invisible to the user● onDestroy() - before activity destroyed● onRestart() - if it was previously stopped, prior to onStart()
  26. 26. Intent & Activity● starting activity explicitly● starting activity implicitly● starting activity for result
  27. 27. Configuration changes● when configuration changes activities are destroyed and recreated by default – place for lots of bugs● behaviour can be changes● it is preferred to properly handle config changes – onSaveInstanceState(Bundle)
  28. 28. User Interface● defined by hierarchy of views● layouts = containers – LinearLayout – RelativeLayout – FrameLayout – AdapterView – ListView, GridView, Spinner● widgets = UI objects – Button, TextView, EditText – WebView
  29. 29. List Widgets● displays a list of items (some view) – ListView, Spinner, GridView, Gallery● use adapter to bind list to data
  30. 30. Resources● drawables – bitmaps, 9-patch png, state-list, layer list, shape drawable, ...● layouts● strings● colors● menus● animations● arrays, ids, dimensions, raw, ...
  31. 31. Screen sizes and densities● How to handle so many different devices?
  32. 32. Resource units● dp/dip – density-independent pixel● sp – scale-independent pixel
  33. 33. Resources● generated file R.java● resource ids● makes resources accessible in the code●● resources can be created in several versions – proper resource is selected according to current device configuration in runtime
  34. 34. Resource qualifiers● screen density – ldpi, mdpi, hdpi, xhdpi● screen size – small, normal, large, xlarge● screen orientation – port, land● language – en, cs, sk, ...● version – v11, v14, ...● since Android 3.2 – w<N>dp – available screen width, w600dp – h<N>dp – available screen height, h720dp – sw<N>dp – smallest width (does not change with orientation change)● combinations
  35. 35. Android version fragmentation● How to handle different API levels avialable on devices?● build target – project.properties – target=android-16● AndroidManifest.xml <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
  36. 36. Android version fragmentationif (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { // only for android older than gingerbread}
  37. 37. Android version fragmentationprivate boolean functionalitySupported = false;static { try { checkFunctionalitySupported(); } catch (NoClassDefFoundError e) { functionalitySupported = false; }}private static void checkFunctionalitySupported() throws NoClassDefFoundError { functionalitySupported = android.app.Fragment.class != null;}
  38. 38. Fragments● a piece of application UI● fragment != activity● fragments used within activities● since Android 3.0● support library v4 backports it to Android 1.6+● introduced to support more flexible UI – phones and tablets together in one app
  39. 39. Threads● main thread = UI thread● do not block the UI thread● use worker threads for time consuming operations● UI toolkit not thread safe – never manipulate UI from a worker thread
  40. 40. Menu● Android pre 3.0 – menu hidden under menu button● Android 3.0+ has ActionBar: – items can be displayed in the action bar – if not enough space the bahaviour depends: ● hidden under menu button, if the device has menu button ● otherwise an overflow icon created in the action bar● menu resource
  41. 41. Dialogs and Toasts● Dialog – floating window screen – standard dialogs – custom dialogs – since fragments used via DialogFragment● Toast – simple non-modal information displayed for a short period of time – doesnt have user focus
  42. 42. Notifications● a message that can be displayed to the user outside your normal UI● displayed in notification area● user can open notification drawer to see the details● app can define UI and click action on the notification● NotificationCompat.Builder
  43. 43. THE END
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×