Tutorials
Charlie's short Ehcache example
Submitted by charlie.collins on Fri, 11/19/2010 - 08:10
Tagged:
It's been a while since I have done a tutorial, so here goes: Ehcache rocks.
I don't really have the bandwidth at the moment to do a proper Ehcache full fledged example, so I'll make this part of the "super short" series (well, short, not exactly super short). To start, Ehcache is a very flexible and powerful open source (and Apache 2.0 licensed) caching engine for Java based apps. There is a lot of "enterprise" talk on the site, justifiably so, as it's part of Terracotta and can be used in a distributed manner, supports overflow to disk, supports overflow to non-heap memory (coolio!), and a lot more fancy stuff, but you can also use it with your plain and simple Java SE app too. (Or your fancy large scale "EE" style app that shuns more traditional EE approaches because it kicks ass with Guice and Guava and so on and doesn't need an app server to do it, but I digress.)
To get started exploring Ehcache you can dive right in on the site, as they have many great code samples and recipes or you can checkout (SVN) the project I'll walk through here as follows (NOTE that I added a space between // and cc so that this wasn't auto-link converted here, you need to remove that space to checkout):
svn co http:// cc-sandbox.googlecode.com/svn/trunk/ehcache_example/ ehcache_example
Android: Use the ViewHolder Luke, and Larry, and Curly, and Moe
Submitted by charlie.collins on Sat, 07/03/2010 - 16:54
Tagged:
This is going to be a quick hit blog post about the Android "ViewHolder" pattern. This is a pattern that many people seem to be at least vaguely familiar with, but not very many actually use (based on open source Android applications and examples/books, etc.).
First some background. Larry, Moe, and Curly were characters from . . . ok, not that much background, but to really make use of the ViewHolder with Android you do need to know what the ListView widget is (a helper for managing views of lists), and that ListViews and generally backed by Adapters (adapters provide data for lists and build views for said data, they can be made from lists of stuff in files, or from in memory arrays, or from databases, and so on).
An example of a ListView in action is seen in the screen shot below.
Backing up your Android SQLite database to the SD card
Submitted by charlie.collins on Sun, 02/21/2010 - 11:43
Tagged:
UpdateThis article describes one way to backup a complete Android database to an external file. Doing this is not an ideal way to backup data, but can be useful in some situations. A better general approach is to import or export data to another format (CSV, etc) and then parse it into your database. This allows you to control the DB schema, and not have to worry about older DB restores with a newer app version, and other related problems. Also, as of 2.2, the Android Data Backup service is available and highly recommended.End Update
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:
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:
Android Application and AsyncTask basics
Submitted by charlie.collins on Sun, 02/14/2010 - 18:30
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:
Sorry, images got lost when server crashed...
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:
Sorry, images got lost when server crashed...
Android SQLite Basics: creating and using a database, and working with sqlite3
Submitted by charlie.collins on Sun, 01/17/2010 - 14:48
Tagged:
UPDATE DISCLAIMERThis is one way to do direct DB access with SQLite on Android, but it's not the only way. I have modified the pattern I personally use somewhat, and it's quite a bit different from the time this article was written (this article is old). I plan to update this article at some point when I have time, but for now just keep in mind that this is meant to get you started, but not be a complete/comprehensive/exclusive approach.
Also, after a server crash the formatting, and some images were lost, these items will be fixed as soon as I get a chance, sorry.
Because I often have to revisit this stuff myself, I thought I would write a quick reference tutorial on creating and using a database with an Android application. This isn't terribly well covered in the Android docs, and though many ContentProvider tutorials exist (such as the Unlocking Android code for chapter 5, and the NotePad tutorial included with the SDK), and these help a lot with general database concepts, they are really more complicated than what a basic application needs - a database to store and retrieve stuff. I will walk through the code and tools for an oversimplified example here, with the ultimate goal of inserting and retrieving some data from an database in an Android app, and then examining the database using a shell and the sqlite3 command line tool. The entire code for this example is available here: http://totsp.com/svn/repo/AndroidExamples/trunk/. NOTE This code was updated for part 2, and part 3 of this series, so it no longer exactly matches this example -- it's still a working sample app, it just now does a bit more than the original. First, to get this rolling, we need to create an Android application that HAS a database. We could use any built in application that has a database just to explore it, such as com.android.alarmclock), but we are going to create one here for completeness. After it's setup, the interface for our application will look like the screen shot shown below:
Also, after a server crash the formatting, and some images were lost, these items will be fixed as soon as I get a chance, sorry.
Because I often have to revisit this stuff myself, I thought I would write a quick reference tutorial on creating and using a database with an Android application. This isn't terribly well covered in the Android docs, and though many ContentProvider tutorials exist (such as the Unlocking Android code for chapter 5, and the NotePad tutorial included with the SDK), and these help a lot with general database concepts, they are really more complicated than what a basic application needs - a database to store and retrieve stuff. I will walk through the code and tools for an oversimplified example here, with the ultimate goal of inserting and retrieving some data from an database in an Android app, and then examining the database using a shell and the sqlite3 command line tool. The entire code for this example is available here: http://totsp.com/svn/repo/AndroidExamples/trunk/. NOTE This code was updated for part 2, and part 3 of this series, so it no longer exactly matches this example -- it's still a working sample app, it just now does a bit more than the original. First, to get this rolling, we need to create an Android application that HAS a database. We could use any built in application that has a database just to explore it, such as com.android.alarmclock), but we are going to create one here for completeness. After it's setup, the interface for our application will look like the screen shot shown below:
Wrapping an Eclipse PDE Build with Maven
Submitted by charlie.collins on Tue, 12/22/2009 - 13:12
Tagged:
A few months back our team at the office decided to buckle down and create an automated repeatable build for a new Eclipse RCP app we are working on - because it's the right thing to do. What follows is most of an article I wrote back then, and never got around to publishing here. This article isn't polished but if I don't hit submit right now, it will never see the light of day again - and I think it *might* help someone somewhere sometime even in less than perfect form, so here goes.
(I updated the CODE and README for this project today - 01.07.2009, haven't really written a proper article yet, but README is better, and tested setup on multiple platforms, win32 and lin32. Check out the screen shot, Windows! Trying to make it nice for the people, since a few of you asked, even as much as I loathe said OS ;).)
My life with PDE Build
Fortunately, Eclipse comes with a lot of support for automating builds in terms of the PDE (Plug-In Development Environment) project which includes an Ant based set of Eclipse Plug-In build tools. Even though Eclipse provides this, we normally use Maven for our builds, so we set out to find a way to use Maven to manage Eclipse PDE. Hence the saga began . . .
Fortunately, Eclipse comes with a lot of support for automating builds in terms of the PDE (Plug-In Development Environment) project which includes an Ant based set of Eclipse Plug-In build tools. Even though Eclipse provides this, we normally use Maven for our builds, so we set out to find a way to use Maven to manage Eclipse PDE. Hence the saga began . . .
Android examples
Submitted by charlie.collins on Wed, 12/02/2009 - 10:04
Tagged:
I answer questions on the Android developers mailing list (http://groups.google.com/group/android-developers) from time to time. Often when doing so I point people to the code examples at the Unlocking Android gCode site.
Just to repeat it, so that maybe more people will realize it's there, all the code for UAD is at the site: http://code.google.com/p/unlocking-android/.
You can browse it by chapter and go right to the examples. It was written for Android 1.1, but all the examples still run fine on 1.5 and 1.6 (I haven't tried them in 2.0 yet, but plan to).
More Unlocking Android code examples up
Submitted by charlie.collins on Wed, 12/03/2008 - 18:25
Tagged:
I completed several more examples for the upcoming Unlocking Android book and posted them at the code hosting site.
Specifically I finished a new project for chapter 11 - Location, Location, Location - which deals with LocationManager, LocationProviders, LocationListeners, MapActivity, MapView and all that stuff (all for the 1.0 SDK). WindAndWaves as it is called, is really more than an example, it's a full fledged app.
Specifically I finished a new project for chapter 11 - Location, Location, Location - which deals with LocationManager, LocationProviders, LocationListeners, MapActivity, MapView and all that stuff (all for the 1.0 SDK). WindAndWaves as it is called, is really more than an example, it's a full fledged app. 






Recent comments
21 weeks 5 days ago
21 weeks 6 days ago
24 weeks 3 days ago
25 weeks 1 day ago
25 weeks 1 day ago
25 weeks 1 day ago
29 weeks 4 days ago
29 weeks 6 days ago
30 weeks 2 days ago
30 weeks 3 days ago