Backing up your Android SQLite database to the SD card

Tagged:

Another useful Android programming tip is to either allow users to selectively backup any database your application uses, or just do it for them in the background (at some interval).

Why is this important? Well, if the user gets a new phone (for whatever reason, lost it, upgraded, chucked it out the window before going kayaking) one of the first things they will do is hit the Android Market again and try to re-download the applications they had (the Market saves this info and makes it easy, well, generally, there are a few quirks, but that is beyond the scope here). Also, they might just want to uninstall your app at some point and later come back to it on an existing phone. Without a database backup they might re-acquire your application but they will be pissed (rightly so) if all the data is missing.

Some applications handle this very well (notably Evan Charlton's Mileage, which is a great app BTW, has always upgraded for me flawlessly -- I don't know if it uses a similar method to what I advocate here or not, but it works very well however it does it), and others don't (Google Listen, I am looking at you ;)).

To that end in this article we are going to modify the AndroidExamples application we have worked on before here at TotSP to include a new Activity that allows users to backup the database. This is really just to demonstrate a few ways to do this rather than an exhaustive example, but it should get you started if you are interested in this area.

Our new version of AndroidExamples (complete code via the link) will have a Menu on the Main activity that lets users go to a new ManageData activity -- as seen in the screen shot below:

Main activity with menu

The American Internet (tm)

Tagged:

While I am catching up on stuff I meant to post about, I just want to make a quick note about this post by Kevin Drum at MoJo. The thing that really stood out was the included quote he cited:

Nancy Scola uses Iran's recent ban on Gmail as an occasion to say this:

No, THEY are the Stupid Ones

Tagged:

Blah blah blah, iPad. Whatever.

Much linked article at Funkatron this week about users and how computers are appliances and we have been giving them the wrong thing for three decades.

Sweet Jesus I get sick of hearing this.

Android Application and AsyncTask basics

Tagged:

Programming on Android is pretty easy. At least it is at first, then the subtleties creep in -- like maintaining state, long running tasks, managing orientation changes, and so on. When you get to that stuff programming Android gets, well, not hard, but let's say more complicated.

The Android APIs are generally very nice, and there are ways to deal with just about any situation, it's just that they aren't always obvious. In this tutorial we will expand on the last one we worked on which covered SQLite and using a database. Here we are going to fill out more details, including adding an android.app.Application object to stash expensive objects and maintain state, adding a few more data operations, and putting said data operations onto a background Thread using AsyncTask (plus demonstrating saving instance state when the screen orientation is changed, and restoring same).

The complete application, which is intended to be very simple, will look like the screen shot below:

AndroidExamples

Vega

Tagged:

This is the tablet I am really waiting for. Again, I can't stand the limited storage, but at least it has an SD slot:




Syndicate content