The Chronicle of an Android Developer Apprentice (3 of 7)

Wisespend app is going to be backed by a SQLite Database. The decision? Not clear. Let’s say that because I had not bothered yet to look for another option of storing data aside from a SQLite Database. By this early version (day two), the database was laughably simple that at first impression, using a database at all is perhaps an overkill but let’s see about that later.

KoinKuLator also built with SQLite Database and the first implementation of it was wrong on so many levels that sometimes, as the data grows, it throws, first a warning that a connection was open and never closed, more often than I would’ve liked, and finally, the dreaded Application Not Responding error box. Romain Guy (or whoever who really said it, all I remember that it was from one of Google IO 2010 keynote) says it succinctly, if your application throws an Application Not Responding, then you did something wrong. No questions necessary. Not the Dalvik’s fault, not the over-engineered Android framework’s fault, not Steve’s faults, it’s yours. Not until version 0.4, which sadly hasn’t seen the light of day just yet, that I implemented a different, more efficient approach to manage a connection to SQLite Database in KoinKuLator (see previous post on how I approached the problem and containing the use of Cursor in a strict container and not throwing/passing it everywhere).

The approach has proved itself to be, if not the most correct approach, an easier approach to be reused.

In essence, the approach was having everything centralized, rather secluded from the rest, while at the same time, maintaining the connection to several tables that sort-of representing the database structure, stored in one single class. The All Knowing Class. Or something like that. Long story short, based on the two tables that I currently produced to satisfy the need of my app, I set up a complete sort-of back-engine for it, from scratch in less than thirty minutes.

The next challenge would be wiring it all up so we get a sense on how the data is going to be created, entered, and managed for the benefit of all. Again, let’s look into my notepad. The three methods I circled are the initial functions I thought I would require and as I had mentioned before, the approach enabled me to setup it quickly. Thus, calling this as a challenge is actually an overstatement.



Now, the final part of this day is what I’d like to call a challenge. Not necessarily that it had a steep learning curve but more because it involves one of the technology I dreaded the most. XML. In this part, I’m setting up the layout to hand proper responses against actions, and to calculate the actions, and finally gave back the results of the actions. Oh, have I mentioned that I dreaded XML? I love writing codes, but writing XMLs aren’t really a walk in the park on a sunny afternoon for me. Heck, just by looking at it, I felt dread creeping up for me. It’s like a silver bullet to my Werewolf being, like a kryptonite to my Superman being.

Alas, a Man’s gotta do what He’s gotta do. Besides, I’m equally excited as I going to implement another thing that is totally new to my experience as an Android developer. Gestures.

I’m using TweetDeck as my choice of Android Twitter client. It had its ups and downs but one particular thing I’d love the most from this app is its swipe left-and-right gestures and I wish to get my hands wet implementing it. Sure, gestures are especially made for touch screen devices and, even if I’m not entirely sure, there bound to be an Android device out there without it. Thus, limiting the exposure of Wisespend app should it ever gets released. However, since my very own device is a touch screen device, and I don’t plan to release this app publicly (unless we decided to launch it), there’s nothing that could stop me from implementing it.

This article is a good point to start and I did almost bullet per bullet implementation out of it. Including, this is I think the most important part, installing a GesturesBuilder to the emulator to record the intended gestures I’d like to recognize in the app, and transferring the resulting library into a folder called ‘raw’ on Wisespend app. Long story short, I did it almost without hassle worth mentioning and thus, after re-implement it in the various places of the screen, ended the second day of the development.

To be continued …

This entry was posted in KoinKuLator, Wisespend. Bookmark the permalink.

2 Responses to The Chronicle of an Android Developer Apprentice (3 of 7)

  1. abangkis says:

    If you want to see how swipe left and right is implemented, just see the AnCha Code.

    For SQLite, this is more of preference than best practice. Anta prefer using a singleton DB class that handle all connection. While I, rather to avoid singleton. While it is a valid design pattern, it circumvent a lot of OOP benefits. You can’t extends or polimorphs the class. I rather use Pooled or Dependency Injection approach for this kind of problem. But every pattern has it uses, since we work on mobile device and didn’t plan for any scalability, the approach is still acceptable, though I didn’t like it.

    My approach is to use a single OpenDBHelper class for each DB (anta also uses this). This class responsibilities is to create the database tables, and upgrade it if a change is detected. One other responsibility is to open the DB instance if weren’t open. The OpenDBHelper then would be passed to the adapter constructor, so the adapter class can get the opened DB instance by calling OpenDBHelper.

    The difference between Anta and my approach is that, like my previous comment, i like to think Activity as an independent entity. That’s why on each Activity I open and close the adapter. A bit more costly but the separation of concern is very clear.

  2. rhama.arya says:

    I’m still using that OpenDBHelper 🙂 But I had decided to not like opening and closing the adapter which would subsequently left me with stray Cursor objects in the Activity(s). Rather, the Cursor objects were contained, squeezed so that only the nutritious ingredients that matters remains, and returned that as one of Type object or the Collection of it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s