Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot

2,544 views

Published on

Gingerbread and Honeycomb
Markus Junginger, greenrobots

Google is developing Android rapidly: Since the release of the Android 1.0 SDK two and a half years ago, Honeycomb is the 9th (!) release of the SDK. Having catched up with its competition in previous releases, Android begins to innovate with new APIs like Near-Field-Communication (NFC). This session keeps developers up-to-date with the new APIs introduced in Android 2.3 Gingerbread and Android 3.0 Honeycomb. Developers will learn how to use state-of-the-art features while maintaining compatibility with devices running older versions of the OS.
Besides NFC, performance is probably the most important advancement in Gingerbread: Android 2.3 got a new parallel garbage collection, an improved JIT compiler and lots of new NDK features for high performance native apps. Also, the SIP API may trigger a new breed of IP telephony apps.
Honeycomb is perceived as the first “tablet version” of Android. One of the most important features are Activity fragments, which become the new building blocks for apps that target both smartphone and tablet screens. Nevertheless, tablets are just one aspect to Android 3.0. For example, developers can now speed up the UI dramatically by activating hardware accelerated rendering. The GPU is also the central part of the new animation framework and the Renderscript engine allowing 3D content and high performance shaders. Together with multicore CPU support, Honeycomb sets the stage for next-generation apps that exploit the desktop-like processing power.
The new APIs in 2.3 and 3.0 are a plentiful resource for developers to make their Android apps unique. This is the session you need to get started!

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,544
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
54
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Droidcon 2011: Gingerbread and honeycomb, Markus Junginger, Greenrobot

  1. 1. New Android APIs:Gingerbread and Honeycomb
  2. 2. New Android APIs:Gingerbread and Honeycomb 24. März 2011 Markus Junginger
  3. 3. New Android APIs:Gingerbread and Honeycomb Markus Junginger @greenrobot_de
  4. 4. New Android APIs:Gingerbread and Honeycomb @greenrobot_de
  5. 5. New Android APIs:Gingerbread and Honeycomb
  6. 6. New Android APIs:Gingerbread and Honeycomb
  7. 7. About me Markus Junginger, founder of greenrobot 2007: First Android app 2001: First mobile project 12 years of Java experience 20 years of development experience Android & Mobile Entwicklung Android Technology Usergroup München
  8. 8. Outline Some history Technical look at new APIs (plus code) Gingerbread APIs – AudioFX, SIP, NFC, strict mode, NDK Honeycomb APIs – Hardware accelerated UIs, Animations, Loaders, Renderscript, …
  9. 9. API Changes History
  10. 10. API Changes History
  11. 11. API Version API SDK ReleasedReleases & Time Level Previews - 2007-11 since 1.0 1 2008-09 1.1 2 2009-02 Release early & often 1.5 3 2009-04 11 official releases 1.6 4 2009-09 29 months 2.0 5 2009-10 Every ~3 months a new 2.0.1 6 2009-12 2.1 7 2010-01 release 2.2 8 2010-05 Android developers: 2.3 9 2010-12 constant progress is 2.3.3 10 2011-02 your chance  3.0 11 2011-02
  12. 12. Android 2.3 Gingerbread Performance (Concurrent GC, ext4, …) Audio Effects SIP NFC StrictMode NDK revamped
  13. 13. Audio Effects MediaPlayer & AudioTrack Available Effects – Equalizer – Bass boost – Environment reverb – Virtualizer – Visualizer App: Real Time Audio FX
  14. 14. Audio Effects MediaPlayer & AudioTrack Available Effects – Equalizer – Bass boost – Environment reverb – Virtualizer – Visualizer App: Real Time Audio FX
  15. 15. Audio Effects aid = getAudioSessionId() // or 0 effect = new BassBoost(0, aid) effect.setStrength(1000) effect.setEnable(true) … effect.release()
  16. 16. Audio Effects: Equalizer android.media.audiofx.Equalizer Frequency bands – Available number of bands getNumberOfBands() – Min/Max Level using getBandLevelRange() – setBandLevel(band, level)
  17. 17. SIP – Session Initiation Protocol Popular for voice and video calls over IP General purpose IM, games, etc. REGISTER INVITE BYE Media separate
  18. 18. SIP – Android Classes SipManager: central for SIP functionality SipProfile: user account data SipSession: session SipAudioCall: convenience for voice calls
  19. 19. SIP – Basics steps Get a SipManager Create a “me” and “you” SipProfile Use SipManager establish a call Once established, start audio
  20. 20. SIP – Code for setup manager = SipManager.newInstance(ctx) builder = new SipProfile.Builder(username, domain) me = builder.setPassword(password) me = builder.build() manager.open(me) you = SipProfile.Builder(uri).build() // URI Example: “+49891234@sipgate.de”
  21. 21. SIP – Code for making a call call = manager.makeAudioCall(me, you, listener, timeoutInSeconds) SipAudioCall.Listener – onCallEstablished(SipAudioCall call) – call.startAudio() call.setSpeakerMode(true) call.toggleMute()
  22. 22. SIP – Availability & permissions Check if SIP is available on device isApiSupported, isVoipSupported Basic permissions – INTERNET, USE_SIP Audio call permissions – RECORD_AUDIO, ACCESS_WIFI_STATE, WAKE_LOCK, MODIFY_AUDIO_SETTINGS
  23. 23. Near Field Communication NFC: wireless communication within ~4cm 13 – 106 Kbyte/s NFC tags variants (e.g. RFID) – Low-end: Read-only and powerless (cheap!) –… – High-end: full OS, interactive Device-to-Device (P2P) Major API additions in Android 2.3.3
  24. 24. NFC: Getting notified by Intent android.permission.NFC <intent-filter><action android:name = "android.nfc.action.TAG_DISCOVERED" / ></intent-filter android.nfc.extra.NDEF_MESSAGES: Array of NdefMessage object Works with API Level 9
  25. 25. NfcAdapter API Level 9 – static getDefaultAdapter() (deprecated in 10) – isEnabled: NFC disabled in system settings? API Level 10 – NfcAdapter.getDefaultAdapter(context) – Methods for foreground tag discovery/push
  26. 26. NFC: Foreground actions Multiple apps can register for NFC tags Foreground NFC: Activity is running  has priority over other NFC apps enableForegroundDispatch: fires Intent (PendingIntent) when NFC tag is read enableForegroundNdefPush: makes a NDEF tag available
  27. 27. NFC: Notes API Level 10: more tag technologies – Mifare, A, B, F, V, ISO-DEP – Filters defined in meta-data XML file Filtering by MIME type (e.g. text/plain) Working with tags is pretty low level  bits & bytes Nexus S must be really close to tag (<4cm)
  28. 28. Strict mode Tool for developers (helper classes) Detect performance violations in threads – Network operations – Disk reads/writes Detect leaks (VM wide) – Activites – Closeable – SQLite objects
  29. 29. Strict mode Ways to react to violations (penalties) – Log, drop box, dialog, or crash Strict mode activated & configured in code android.os.StrictMode and inner classes – Policies – Builders
  30. 30. Strict mode – thread policy code p= Builder().detectAll().penaltyLog().build() StrictMode.setThreadPolicy(p) Example log with stack trace 03-19 20:21:44.292: DEBUG/StrictMode(32242): StrictMode policy violation; ~duration=336 ms: android.os.StrictMode $StrictModeDiskReadViolation: policy=279 violation=203-19 Note: MapActivity triggers violations
  31. 31. NDK in Gingerbread GCC 4.4.3, ./configure && make C++ STL (Standard template library) Native Activities Less Java wrappers nessesary – Input and sensor access – Audio (OpenSL) – Windows management / pixel buffers – Direct access to assets in APK
  32. 32. Android 3.0 Honeycomb Fragments (conceptual) Hardware accelerated UIs Action Bar Loaders Animations Renderscript And more…
  33. 33. Hardware accelerated UIs Graphics library Skia: CPU based until 2.3  Software rendering, sometimes slow GPU based rendering is faster (mostly) Switched off by default Manifest entries for application & activity: android:hardwareAccelerated=„true“ Control for windows and views in code: view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
  34. 34. Hardware accelerated UIs, but... Hard to test – No Android 3.0 device in Germany yet – Emulator falls back to software rendering (which is really sloooooooooooooooow) Not all operations are supported Some operations render differently Bitmaps must be uploaded as textures
  35. 35. Loader: Asynchronous loading Loaders address problems of AsynchTask – Don’t restart after configuration changes – Ability to monitor data changes AsyncTaskLoader http://code.google.com/p/android/issues/detail?id=14944 CursorLoader for ContentProviders LoaderManager from activity or fragment
  36. 36. Using a CursorLoader getLoaderManager().initLoader(0, null, l) Implement LoaderCallbacks – onCreateLoader: create loader here – onLoadFinished: receive the result – onLoaderReset: clear the result Creating the CursorLoader: like ContentResolver.query (URI, projection, selection, sort order)
  37. 37. Property Animations ValueAnimator: changes value over time ObjectAnimator: applies value to an object Animation Hello World: View text = findViewById(R.id.text); ObjectAnimator anim = ObjectAnimator .ofFloat(text, "alpha", 0f, 1f); anim.setDuration(2000); anim.start(); Much more: sets, listeners, interpolators,...
  38. 38. Renderscript Portable high performance (vs. NDK) Intermediate LLVM byte code Written in C (C99 standard) Compiled and cached on the device May use CPU or GPU (or even a DSP) Native Renderscript APIs – Logging, Graphics, Memory Doesn’t run on emulator, hard to debug
  39. 39. HC: A lot more to explore… New UI widgets, e.g. StackView Improved home screen widgets System clipboard framework Drag & Drop Media, e.g. HTTP adaptive streaming JSON streaming …
  40. 40. So Honeycomb is cool, but… (Nevertheless: being among the first may be a good strategy)
  41. 41. Android Compatibility package Downloadable through SDK Manager Some of 3.0 APIs for Android 1.6+ – Fragments – Loader – Utils Include as jar/source (~100k) Package android.support.v4  won’t use updated APIs on level 11+
  42. 42. Thanks! Q&AMarkus Jungingermarkus@greenrobot.dehttp://greenrobot.deTwitter: greenrobot_deWe‘re hiring 
  43. 43. Thanks! Q&AMarkus Jungingermarkus@greenrobot.dehttp://greenrobot.deTwitter: greenrobot_deWe‘re hiring 
  44. 44. Fragments Modular approach to arrange the UI Fragments can be (re)used in activities Target multiple device categories
  45. 45. Fragment complexity Activities are not trivial  Lifecycle & process Fragments have a lifecycle, too Interaction with activities Fragment transactions Android just got more complicated powerful
  46. 46. Action Bar Part of Honeycomb’s Holographic theme Quick access to Options Menu items <item android:showAsAction="ifRoom" … No room left: overflow menu
  47. 47. Action Bar Part of Honeycomb’s Holographic theme Quick access to Options Menu items <item android:showAsAction="ifRoom" … No room left: overflow menu
  48. 48. Action Bar, take me home! App icon (by default) when onOptionsItemSelected() is called – Check for android.R.id.home – Go to „home“ activity (Intent.FLAG_ACTIVITY_CLEAR_TOP)
  49. 49. Action Bar, take me home! App icon (by default) when onOptionsItemSelected() is called – Check for android.R.id.home – Go to „home“ activity (Intent.FLAG_ACTIVITY_CLEAR_TOP)
  50. 50. Action Bar: Views and Tabs Place custom layouts in the action bar <item android:actionLayout="…" … /> And views (use fully qualified class name) <item android:actionViewClass="…" … /> Tabs use Fragments ActionBar: newTab(), addTab() TabListener adds/removes Fragements

×