My experiments with writing my little Android app have gone better than I expected and so far I’ve yet to find anything that I’m unable to do. Of course all these small building blocks need to contribute to a whole for them to be useful, so the next step is to try and build an app as so far I’ve just been bolting bits of code onto a single activity to see if they work 🙂 Hardly a useful strategy at this point!
Taking all the small pieces of code and moving them into their own classes was my first step and that worked well enough. My Java foo is certainly not strong (if I have any at all), but this was straightforward enough.
I don’t think the app is overly ambitious (of course I may be wrong) but as I’ve not written anything like this before I’m going to outline what I’m trying to do and the issues I’m pondering. As I find solutions I’ll try and add them in the hopes it may help others. Of course, if you have solutions then you can always send them my way as I welcome all feedback!
The app will basically look for a number of services and then gather information from them and provide an aggregated view of the information for the user. For the most part the gathering will be done without user involvement, so I’m writing this as a service which will run in the background. Without the service running and it’s initial work done there isn’t anything to be displayed, so it needs to be started as soon as possible. I don’t want to start it at boot as it will just use resources that are better conserved on a phone, so currently it gets started by the main activity. Of course the activity also needs to [bind to the service](http://developer.android.com/reference/android/content/Context.html#bindService(android.content.Intent, android.content.ServiceConnection, int)) to provide access to it’s information, so the activity waits a short period then binds. This seems a little clumsy but I’m not sure how else to do it?
As all the activities connect to the service there seems to be a lot of duplicate code going to be needed, so I guess I should abstract that out into a separate class that underpins the individual activities, but as the activities aren’t all extensions of the basic Activity class (some extend the ListActivity) this isn’t as straightforward as I’d hoped. I really try and avoid duplicating code but until I have a solution for this I’m going to keep things simple and just duplicate.
The other big question I have is around the lifecycle of the app. When the app is paused and then resumed it’s not possible to know which activity will be displayed, so how can I ensure that the service has been started? It’s likely I’ve just not fully grasped the pause/resume mechanics, but it’s something that is unique to mobile apps and as such something I’ve not come across before.
At least I’m making progress 🙂