What's new in Android 2.0? Part 2: Developer features

What's new in Android 2.0? Part 2: Developer features

Summary: Android 2.0 ("Eclair") is an evolutionary version of the Android platform. Despite its version number, it's not as big a change as going from 1.1 to 1.5 ("Cupcake"). However, it does bring a number of notable features to the platform. This article samples the goodies that Google sprinkled on top of Eclair just for developers.

SHARE:
TOPICS: Mobility
6

After months of speculation, Android 2.0 ("Eclair") was officially released this week by Google. To be more precise, the Software Development Kit (SDK) for Android 2.0 was released, so that developers can get a head start on 2.0 development before the new devices with 2.0 hit the market. It's not much of a head start, though, because the new devices may will be on sale as early as next week, or by the end of November at the latest.

[ See Motorola DROID on Verizon: Is this the iPhone killer you're looking for? for the first Android 2.0 phone. ]

This is the second of a series of 3 articles covering what's new in this new release. Part 1 covered user features and availability, this part will cover developer features, and part 3 will try to answer any other questions you might have about the new platform. You should read part 1 first, if you haven't already.

Should I stay or should I go now?

In the announcement of version 2.0 on the Android Developer's blog, Xavier Ducrohet wrote:

Over the next few months, we expect to see more and more Android devices being released. These devices will be running Android 1.5, 1.6, or 2.0. We are also planning a minor version update of Android 2.0 towards the end of the year, and that will be the last update for 2009.

That's right, folks - by the end of this year there will be 4 different versions of Android running in the field. It's going to be a challenge for developers to keep on top of this. One thing seems clear - all Android devices will not automatically be upgraded to the latest version:

  • Android 1.5 provides the base functionality common to all versions of Android.
  • Android 1.6 adds support for screen sizes smaller and larger than HVGA 480x320.
  • Android 2.0 adds support for multi-touch and virtual keys, among other things.
  • Android 2.1 will probably be a minor bug-fix version.

With rare exceptions, 1.5/1.6 apps will run fine on 2.0 phones. Most apps will not need the new features that 2.0 brings, so they can continue to use the 1.5 SDK and get the greatest possible reach. Other apps can test to see if they're running on 2.0 and only use new features if they are available. A few apps, however, will want to require 2.0 and rely on its features even if it means they can only be run on a few new devices (for now, anyhow).

Continue reading: What's new in Android 2.0 for developers >

There is no spoon

The first thing you'll notice about the new Android 2.0 SDK is... that there is no Android 2.0 SDK. It's called "SDK Tools, Revision 3". Why? Because of all those versions mentioned before. The idea is that you'll download the "SDK Tools" once, and then install "packages" for different Android Platforms you want to support. I recommend you install the 1.5, 1.6, and 2.0 modules as a bare minimum. Also, be sure to install the Google API module if you're going to use Google Maps. Heck, just install everything. Twice.

And don't try to update from your existing 1.6 SDK. I don't care what Google says - start fresh. You'll need a new version of the Android Eclipse plug-in too. That one you can upgrade.

Nine hundred ninety-nine bottles of pop on the wall...

There are a ton of new developer-oriented features and APIs in Android 2.0. "A ton" equals 999, if you just go by the API Differences Report. The following are the most important ones I feel you should know about:

  • MotionEvent can now report simultaneous-touch information for devices that support it. Up to three pointers can be tracked simultaneously. Why three?
  • KeyEvent has new key dispatching APIs, to help implement action-on-up and long press behavior, as well a new mechanism to cancel key presses (for virtual keys).
  • Google Gears is deprecated, and its functionality has been folded into the WebView class. For example, there are new APIs to get your GeoLocation or store data in a web database.
  • Bluetooth enhancements including peer-to-peer discovery (the android.bluetooth package).
  • Centralized account manager API, securely stores and accesses authentication tokens or passwords (the android.accounts package). The API can support asynchronous long-running network-based authentication methods.
  • New APIs for sync adapters to connect to any backend. You could use this to synchronize data with a company database or third party mail server. Authentication is provided by the centralized account manager.
  • New contacts APIs and reusable contact badges (for apps that interact with the user's contact list).
  • New Service life-cycle APIs.
  • New APIs for retrieving memory usage statistics on other applications.
  • New APIs for setting the home screen's wallpaper.
  • New constants that allow a window to wake up the screen when it is displayed and show the window even if the screen is locked. This allows applications to more cleanly implement things like alarm clocks that should wake the device.
  • New Intent APIs that broadcast the docking state of the device and allow applications to launch special activities when the device is placed in a desktop or car dock.

Continue reading: What's new in Android 2.0 for developers >

What about onBackScratched()?

The KeyEvent changes might break older applications that rely on performing an action on the key-down event for the HOME, MENU, BACK, and SEARCH keys. Those will no longer fire on Android 2.0. The solution is to use a new method like onBackPressed(), or to capture both the key-down and key-up events and use a flag to track the state of the event, performing the action on key-up only if key-down was pressed and focus hasn't changed. Or even better, don't try to capture these buttons yourself - let the Android system do it.

The foreground background service

Another possibly breaking change in Android 2.0 is the deprecation of the Service.setForeground() method. Actually it wasn't just deprecated, it was turned into a no-op. According to the documentation,

This method has been turned into a no-op rather than simply being deprecated because analysis of numerous poorly behaving devices has shown that increasingly often the trouble is being caused in part by applications that are abusing it. Thus, given a choice between introducing problems in existing applications using this API (by allowing them to be killed when they would like to avoid it), vs allowing the performance of the entire system to be decreased, this method was deemed less important.

By default services are run in the background, meaning that if the system needs to kill them to reclaim more memory, they can be killed without too much harm. But if killing your service would be disruptive to the user, such as if your service is performing background music playback - the user would notice if their music stopped playing - you can tell Android it's a foreground service using the new Service.startForeground() method.

Hit the snooze button

As an example of what you can do with the new 2.0 API, look at the new Motorola Droid phone. When you insert it sideways into its cradle, an app uses the docking broadcast event to bring up an alarm clock application. Eventually the screen turns off and the key lock is enabled, but when your alarm goes off it can turn on the screen and display the app's alarm clock screen. And voila, you have yourself a very expensive alarm clock. You can imagine something similar happening when you plug your phone into a car dock like the one TomTom makes for the iPhone. It could bring up your favorite GPS tracking application without your having to search for it.

Continue reading: What's new in Android 2.0 for developers >

Closing arguments

Android 2.0 ("Eclair") is an evolutionary version of the Android platform. Despite its version number, it's not as big a change as going from 1.1 to 1.5 ("Cupcake"). However, it does bring a number of notable features to the platform. Existing applications, especially those that were already adapted to run with multiple screen sizes on Android 1.6 ("Donut"), will run just fine on version 2.0 devices. New applications can take advantage of new features such as multi-touch and BlueTooth discovery if the hardware supports it.

Unfortunately there will not be a quick and automatic transition to 2.0 like there was with version 1.5. For one thing, device manufacturers are just now coming out with 1.6 devices, and some are even running 1.5. The great HTC Hero phone, for example, is still running 1.5 (albeit with a few patches for things like multi-touch).

While 2.0 is all new and shiny, keep in mind that no devices run it right now and only 2 are expected to run it by the end of the year. Some devices may never see any version beyond 1.5 or 1.6. I predict the tipping point where 2.0 devices outnumber 1.5/1.6 devices won't occur until the middle of 2010. Just keep that in mind when you're deciding which version to target with your next killer app.

Topic: Mobility

Ed Burnette

About Ed Burnette

Ed Burnette is a software industry veteran with more than 25 years of experience as a programmer, author, and speaker. He has written numerous technical articles and books, most recently "Hello, Android: Introducing Google's Mobile Development Platform" from the Pragmatic Programmers.

Kick off your day with ZDNet's daily email newsletter. It's the freshest tech news and opinion, served hot. Get it.

Talkback

6 comments
Log in or register to join the discussion
  • APIs for sync adapters

    Where are the new APIs for sync adapters? I'm interested in this, but I couldn't locate them.
    os2baba
    • Re: APIs for sync adapters

      It looks a little sparse right now but I found these mentions:

      http://developer.android.com/reference/android/content/AbstractThreadedSyncAdapter.html

      http://developer.android.com/reference/android/content/SyncAdapterType.html

      http://developer.android.com/reference/android/content/SyncContext.html

      http://developer.android.com/reference/android/content/SyncResult.html

      http://developer.android.com/reference/android/content/ContentResolver.html (search for "sync")

      Ed Burnette
  • Develop for 2.0

    1. An app of any complexity is going to take several months to code, debug, test, re-code, etc.

    2. People that spend the money for a 2.0 device want to be able to use (show off?) their capabilities. They are far more likely to spend $$$ on apps than Joe "I don't need the latest features so I'll stick with what I have". He is not your market.

    3. I am going to go out on a limb and say 2.0 will have 70% of the droid market in a year.
    No_Ax_to_Grind
    • So when Windows 7 came out...

      ...did you rush to produce Windows 7-only programs? Probably not. But it would be smart to test your programs on Windows 7 to make sure it works ok. The next step would be, if there was something easy you could add on for users running W7 without making it unusable on other versions, you could add that. You wouldn't drop support for the older versions (Windows XP and Vista) until you either were forced to or almost all your customers had upgraded.

      The same goes for Android -- just substitute Android 2.0 for Windows 7, and 1.5/1.6 for XP/Vista.
      Ed Burnette
  • RE: What's new in Android 2.0? Part 2: Developer features

    The greater portion of that message was probably correct, but the "months to code and debug" part is not necessarily true. Sometimes all it takes is tweaking existing source code, and sometimes a person can write a new program in a few hours -- given enough coffee, or in a frenzy of creativity.
    darndan
  • RE: What's new in Android 2.0? Part 2: Developer features

    Thanks Ed.
    os2baba