Archive for the ‘Android’ Category

Unlocked Android Dev Phone on AT&T

Can you use your Android Developer Phone with AT&T? Andrew provides a detailed experience report.

Short answer: yes.

IDEA 9 Android Support

IDEA 9 Android support is looking good.

State Capitals 1.0.2

I released State Capitals version 1.0.2 tonight. This is an Android flash-card app for U.S. State Capitals.

To find it, just go to the Android Market and search for “State Capitals”.

This release does not add any new features. Instead, I focused on:

  • Improved performance
  • Reduced memory allocation, resulting in less garbage collection
  • Smoother animation

The animation is the biggest visible change. In the old version, a fling gesture moved to the previous or next card. My approach was:

  1. Use a standard Android animation to slide the activity to the left or right, depending on whether you were moving to the next or previous card
  2. At this point, you’d see a black screen. This is where I loaded the next bitmap, and the garbage collector generally ran
  3. Use another animation to slide the activity back onto the screen. (with the new bitmap)

If you’ve used the app, you also know I spin the card around using an animation. Every time onDraw(…) was called, I’d paint the card border, the state bitmap, and the text on top of the state. This made the code very inefficient.

The New Approach

In the new version, you can slide your finger on the screen, and the card moves with your finger. You also see the previous or next card directly adjacent to the current card.

I also generate a bitmap for the entire screen, and cache that bitmap. So when an animation occurs, I simply paint the cached bitmap.

Finally, I eliminated many memory allocations. For example:

  • I only save your settings when onPause(…) occurs. Before, I was writing to preferences every time something changed, which resulted in large numbers of object allocations
  • I eliminated several Lists and Maps, replacing them with simple arrays
  • I reuse the same Bitmap and Canvas objects over and over

If you want to learn more, check out “Google I/O 2009 – Writing Real-Time Games for Android”.

My focus on reduced object allocation is a direct result of watching that video, and it made a huge improvement to my app.

Swiss Codemonkey: Avoid Them

Last week I installed a goofy app “Arnold Soundboard for Android” from Swiss Codemonkeys. I shouldn’t have, because the app requested network access.

Today, I received what appeared to be an SMS message. It had a little “thumbs-up” icon, and it said something like “A friend recommended an app!”. Clicking on the link brought me to the Android Market link for the Horoscope Widget, also from Swiss Codemonkeys.

Malicious

I strongly suspect this message came from the Arnold Soundboard app, but I can’t really prove that. I did report it as a possible malicious app, and I recommend people avoid apps from Swiss Codemonkey. (or any other apps that request network access even when they don’t do anything network related).

If you are an application author, feel free to advertise your other apps. But don’t send messages pretending to be “recommendations” from alleged “friends”.

Android Device Database

By the end of 2009, Google predicts there will be at least 18 Android phones. This is great news, but it also means developers must create apps that work on a wide range of devices. Each phone may have a different screen resolution, support different sensors, and could report a different User Agent string when accessing web sites.

The Idea

Create an online, interactive Android device database. This web site will list every Android device, along with complete specifications. The site should use AJAX so visitors can sort, search, and filter efficiently. Using this site, people can see:

  • Detailed specifications for specific phones
  • Sort by screen size or any other attribute
  • Filter to show phone supporting the accelerometer or any other combination of features
  • Select several phones and compare their features side-by-side
  • etc…

Android Client Software

Part of this project involves a client application running on Android. This application will inspect all of the phone’s features and upload them automatically to the Android device database web site. For example:

  • Screen resolution
  • Keyboard type (physical or soft)
  • List of supported sensors
  • Software version information
  • OpenGL features
  • Anything else we can detect without violating user privacy…

This information is easy to gather, and can be POSTed to the web site as XML or JSON. Once submitted, the information is automatically entered into the phone database along with the User Agent the phone sent.

How I Would Do It

I don’t have time to create this app (I’m working on something else). If I did have time, here is how I’d do it:

  • GWT 1.6 for the web site
  • Google App Engine for the server hosting and data storage
  • Android SDK for the client (duh)
  • Google security to prompt for username/password when submitting a new report
  • Host everything on Google Code with an Apache 2.0 license
  • Use Mercurial for the source code

Moderation Queue

This is a technically easy project. The main challenge I anticipate is fighting bogus submissions and spam. You could implement a moderation queue for any new submissions. Once someone with a T-Mobile G1 submits the first report, all subsequent submissions from identical phones should be identical, and would thus be automatically ignored.

You may need to moderate and approve brand new submissions from phones that are not yet recorded in the database.

Other Ideas

It might be nice if people could post pictures of each phone on the web site. This would be a manual process, as the phone software cannot take a picture of itself.

So what do you think? Is anyone interested in creating this application?

Apple is not Worried

Is Telegraph.co.uk a real web site, or is it a parody site like The Onion? Let’s take a look at some claims made in this article about the Vodafone Magic phone.

Vodafone’s new flagship is superb – Apple should be worried – yet the packaging for the HTC Magic is discreet.

OK. Apple should be worried..about what? Let’s see.

…whereas the Storm endured weeks of teething troubles prior to evolving into the best business handset on the market, the Magic weaves its spell from the moment you turn it on.

Does this phone offer Exchange support? Because without that, it’s not going to make inroads into the “business market”.

The handset also lacks a standard jack for headphones; an adaptor, however, is included in the box.

WTF? Another stupid non-standard headphone jack. Awful. Carrying an extra adapter is a pain. I have used headphones with my G1 exactly zero times. It needs a standard jack.

Three aspects are particularly impressive: the first is the touchscreen, which works as effectively as the iPhone’s, and consequently is among the best on the market.

Absolute horse shit. Ask any parent who has these two things in his or her house:

  1. An iPhone or iPod Touch
  2. A toddler

Multitouch is essential. A single touch screen isn’t even in the same league as iPhone. A toddler knows this intuitively. Watch them pinch the screen when viewing photos and playing games on an iPhone.

I have handed my G1 to family members and friends, and when they go into a picture, web page, or map…they instinctively try multitouch gestures.

I love Android, but let’s not be naive about how these phones stack up against the iPhone.

Google I/O 2008 – Dalvik Virtual Machine Internals

I’m gonna try this link again…

Not a Memory Leak

Yesterday, I posted this picture from the Snake game on my G1 phone:

I received this comment from Alex:

Snake with open/close is a memory leak . As a weather has nothing to do with Android just bad app.

Duplicating the Bug

Here is how I duplicate the bug:

  1. Start playing a game
  2. Change the phone orientation, i.e. open or close the keyboard drawer
  3. Push the trackball up to resume the game

Just repeat steps 2-3 a few times until it crashes, it usually takes a few tries. Is this a memory leak, as Alex suggests?

Diagnosing the Bug

  1. First, install the free Android SDK. Google provides excellent instructions, so I won’t explain it here.
  2. Configure your G1 phone for USB debugging. From the home screen, go to Menu -> Settings -> Applications -> Development, and select USB debugging.
  3. Now connect your G1 phone to your computer via the USB cable.
  4. Run ddms to start the Dalvik Debug Monitor. You’ll find ddms in the tools directory where you installed the Android SDK.
  5. Make Snake crash and find the stack trace in the Log.

As you can see, this is an ArrayIndexOutOfBoundsException, not a memory leak. Here is the complete stack trace:

java.lang.ArrayIndexOutOfBoundsException
    at com.example.android.snake.TileView.setTile(TileView.java:150)
    at com.example.android.snake.SnakeView.updateApples(SnakeView.java:434)
    at com.example.android.snake.SnakeView.update(SnakeView.java:405)
    at com.example.android.snake.SnakeView.setMode(SnakeView.java:336)
    at com.example.android.snake.SnakeView.onKeyDown(SnakeView.java:279)
    at android.view.KeyEvent.dispatch(KeyEvent.java:718)
    at android.view.View.dispatchKeyEvent(View.java:3154)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:734)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:734)
    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:734)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1589)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1084)
    at android.app.Activity.dispatchKeyEvent(Activity.java:1856)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1560)
    at android.view.ViewRoot.deliverKeyEvent(ViewRoot.java:1616)
    at android.view.ViewRoot.deliverTrackballEvent(ViewRoot.java:1508)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1201)
    at android.os.Handler.dispatchMessage(Handler.java:88)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3739)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
    at dalvik.system.NativeStart.main(Native Method)

Avoiding Bugs Like This

I find that most Android bugs occur when Activities pause and resume. Changing screen orientation is a great way to crash many applications. That’s because orientation changes trigger lifecycle events. These events will occur at inopportune moments, such as when you receive phone calls or the user hits the Home button.

Applications that do not properly react to onPause(), onResume(), and other such methods will eventually fail.

You can use the UI/Application Exerciser Monkey to stress test your application. In the emulator, you can simulate incoming phone calls, which will pause the current Activity. You should also open and close the keyboard — repeatedly — while your application is performing tasks.

In summary, you need to brutalize your applications. Try really, really hard to break them. Android is a challenging environment because you must carefully manage threads, react to a complex series of lifecycle events, and deal with limited resources.

Android Hall of Shame

A few minutes ago I tried to take a picture with my G1 phone. My phone failed:

So I grabbed my Canon PowerShot SD1100 camera and snapped the picture shown above. My Canon camera never shows a “Force Close” error. It just works. I expect the same user experience from my phone. Is that an unreasonable expectation?

Here is the Weather Channel Android application, one of the most popular apps in the Android Market. It Force Closes becomes unresponsive from time to time. To get this picture, I simply tapped the tabs quickly:

Next I opened the Snake game. I opened and closed the phone a few times and…well, you know what’s coming next:

This is not good enough.

Android Popping Bubbles Example

This example is a bit simpler than the bouncing ball demo I posted ten days ago. When you tap the screen, a bubble appears. This bubble grows until it pops. Tapping several times makes several bubbles.


Android Bubbles Example from Eric Burke on Vimeo.

Goals:

  • Animate many different objects. In this case, growing circles. There is only one background thread running the “game loop”. It keeps a list of circle positions and sizes. You could easily apply this same concept to any kind of animation.
  • Play a popping sound when each bubble pops.

The pop sounds like crap on the phone, even worse in the video. You can find the original popping sound on freesound.org. I clipped the sound (using Audacity) to make it play faster, I suspect it can be improved with some work.

You can find the source code for BubblesModel.java and BubblesActivity.java on GitHub.

This app still has a serious bug, described in this Android Developer’s Post. Let me know if you know how to fix this!

Aside from that bug, this is not production-ready code. It is pretty sloppy with memory, copying a List of Bubble objects on each iteration of the game loop. I opted for brute force synchronization just to make it work. For a real game, I’d spend more time on fine-tuned locking and sharing objects to minimize garbage collection.