Entries Tagged 'Android' ↓

Android Resources + SQLite. || Pick a number, any number.

So, you have a nifty neat application that is storing data based on user input. You allow the user to choose a resource (an icon, maybe a sound file) to be stored with that data record. Everything is going great until you add new resources to your project. Suddenly the icons are mixed up, no longer the icon originally chosen. Welcome to the world of machine-generated code.

The solution is rather simple, just not presented anywhere in the Android docs. We’ll create an Enum that associates the Resource IDs with our own local IDs. This way, we can store the local IDs, so that the SDK can change the resource IDs as much as it wants. Full code for the enum is at the bottom.
Continue reading →

Android DataServices – DB4O

You’ve been through the Notepad example, and you’ve seen my enhancements in the previous post.  But what if you don’t want to have to worry about schema updates and figuring out how to store dates/images/whatever in SQLite?  What if you just want to store your objects without all of the SQL-hassle?

Enter Object Oriented Databases.

OODBs are great for small and simple databases, letting you write the fun(ctional) code without the drag of SQL.  We’re not talking ORM or Hibernate, with cleverly-hidden SQL.  Just simple store(MyObject) and we’re done.

The source code is found in the same place as the DataServices and SQLite project:http://svn.hat6.com/hat6public/DataServiceExample/trunk.
For all of this wonderful functionality, we’ll be using DB4O.  They even have a page dedicated to Android, though the source they provide won’t build.
Continue reading →

Android DataServices – SQLite

You’ve made your way through the Android ‘Notepad‘ tutorial, but find yourself wanting more?  Maybe you want to deal with Typed Objects instead of all of these strings everywhere? While this code isn’t generic enough to paste into your app and use as-is, it is simple enough to adapt to your own typed objects.  Using the Interface described here makes it super easy to change the way you are storing your data, without having to refactor your app itself (imagine a hybrid online/offline storage, or as we’ll see in the next post, an Object Oriented DataBase[OODB]).

If you’d like to follow along in eclipse, source code is found here: http://svn.hat6.com/hat6public/DataServiceExample/trunk.
Continue reading →

Android DataServices

So, you have an Android app, and you need to store your data.  The Android ‘Notepad‘ tutorial will show you the basics of SQLite, and I’ve modified their code quite a bit for my DataServices example project.  The one thing I don’t like about their example is that the app itself knows that the data is stored in SQLite.  While it is just an example project, I feel it’s setting a very bad example.  So I’ve created a bit of abstraction and added an interface so that the SQLite implementation can be swapped in and out for any other storage service.

Below we’ll examine the IReminderDataService interface, which provides some basic data storage functionality.  I’ve implemented two different storage mechanisms: visit SQLite and DB4O posts for specifics.
Continue reading →

Introducing Android to the concept of ItemRenderers

Project With Source Now Posted, See: http://hat6.com/2009/11/27/itemrenderers-updated/

Coming from the Flex world, it’s strange not to see the idea of “ItemRenderers” in Android.  Customizing the way a List Item looks is much more manual than in Flex, so I’ve come up with a ListAdapter that allows for some of the flexibility/framework-ness that I enjoy in Flex.

I started from this tutorial and modified it to be more Flex-esque.  I’ve tried to keep things as simple and generic as possible.  This is my first draft, so it’s pretty bare-bones, but it does what is needed initially.
Continue reading →