Wednesday, November 11, 2009

An Android Glitch

On the whole, I'm reasonably happy with the Android OS, but there is one problem I have observed in two unrelated applications and so suspect is coming from the operating system.

One of the applications is DocsToGo, which provides, among other things, a word processor that can read and write MS Word documents. I call up a document, perhaps edit it a bit, then switch to doing other things with the phone. Eventually I go back—and get a message telling me that the program was shut down improperly and asking if I want to retrieve the document I was working on.

The other application is Divide and Conquer, a mildly entertaining game. I get to level seven, switch to doing something else with the phone. Eventually I go back—and discover that I am back at the beginning of the game.

I suspect I know what is happening. Android only keeps a small number of applications open at once. After I switch from one program and run several others, the first gets dropped—forcibly shut down. My guess is that the process doesn't involve actually waking up the program and telling it that it is about to be shut down, so there is no way the program can respond by saving its present state. From the standpoint of DocsToGo, it is as if the computer crashed while it was suspended.

Perhaps someone out there who knows more than I do about the Android internals can tell me if this guess is right, and if there is some way of programming around the problem. Also whether the problem still exists on Android 2.0.


2 comments:

Matt Brubeck said...

I'm an Android app developer. You're correct that the Android operating system automatically shuts down programs in the background when it runs low on memory. However, it actually does notify the program before it is shut down, so that it can save its state. Applications are supposed to implement an onPause method to handle this event.

If your application is losing its data when you resume it, either it does not correctly handle onPause, or it has a bug (e.g., it is crashing before it manages to save its state).

This is not changed in newer versions of the operating system, but it may be triggered less often on phones with more RAM. (I believe you have the T-Mobile G1 / HTC Dream, which has 192 MB of RAM, while more recent handsets have 256 MB or more.)

SB7 said...

Looks like Mr. Brubeck beat me to it. He is quite right -- it's up to the app developer to implement that behavior correctly.