Monthly Archives: August 2009

Multitasking Mobile Metagenomics

Triple M?! You betcha! Up until about five minutes ago, I was under the impression that when somebody navigated away from Mobile Metagenomics, I had to drop everything. I envisioned stopping my download thread, saving current results, saving iteration values, saving a mode variable, and whatever else was necessary to later restart whatever MM was doing. I even wrote pseudocode for it yesterday, and spent the first half of today implementing it.

I’m glad I decided to take a short break and read about Android stuff, because as it turns out I was flat out wrong about onStop(). Apparently, I can actually let my worker thread busily download new chunks of data into MM while a user is checking their email, making phone calls, IMing their friends about how cool Edwardslab is… And if the phone needs additional memory and has to kill the MM process, I believe I can actually store & create aforementioned variables at that point. Which is cool not only because we get to save our progress, but also because I don’t have to crumple up two pages of pseudocode Laughing

I was starting to feel like MM might be getting close to finished (unless Rob and I do some kind of cool file browser-esque navigation of results, in which case I’ll probably have to spend a week just learning the Biology), but now I have a new thing for my brain to chew on for a bit. I feel like doing the annotation downloads as a background process adds quite a bit of value to MM as an application. The user may choose to view the results as they happen (which is the original intent of Real-Time Metagenomics to begin with), but they will no longer be locked into MM. Even as a developer I hate the notion of “okay I started MM, now lets have it sit there for 3 minutes”, so I can only imagine how much users would’ve disliked that.

As far as progress since my last post about what I’m actually working on, I’ve got a fair amount of error detection/recovery implemented in both Genome Search and Mobile Metagenomics. I’m not going to say that I can detect and recover from everything (because I’m sure we’ll find some obscure way to break the app), but it is looking pretty solid from my tests. Through normal use, it shouldn’t do anything weird anymore. Note that ‘normal use’ still confines us to being locked inside of MM unless we want to lose all progress. That is, until I get this next part figured out!

Android: Nuts and Bolts V

This episode of Nuts and Bolts puts us back on course with what I had originally planned as N&B 3 – “Threads, or, How to Not Blow Up Your New User Interface”. We’ve already discussed how to make a UI, and we’ve talked about how to make it work. The next logical step is to learn how to make our application do something meaningful. For simple applications this may not mean using threads, but any time your app needs to A. sit around and wait for something, or B. do intensive computations, you will need Threads. Become an Android sewing master by clicking the “Read More“!


Continue reading

Adding Error Recovery to GS / MM

One of the tasks that I’ve been meaning to work on for some time is doing some actual error recovery for MM. I realized however, that not only is this a pretty big problem to get a hold of, I also never did it for GenomeSearch. Since we want to put both on the market someday anyhow, I figured I may as well start with the more simple app and get some practice.

I took Daniel’s network status checking snippet, stripped out the textview stuff specific to his test app, and turned it into a small boolean method for GS to query. Now, when the app launches, it checks for network availability before it tries to fill up the list of Genomes. If it should fail, I have an alert dialog method which either recurses on itself until the network is available, or closes the program. The user is able to click ‘Retry’ or ‘Quit’ to achieve either option. In the future I may want to add an arbitrary delay between re-tries, or we may choose to just leave it with no delay.

I also put into place a little bit of code to let the user know if something goes wrong anywhere along the GenomeSearch process. This part isn’t quite done yet; I had most of the code in place last week, but due to some complexities I didn’t anticipate I had to not use any of the cool Toast error pop-ups. (Specifically, the methods I put the Toasts into are called from both the UI thread and a worker thread. The worker thread isn’t allowed to perform the toast pop-ups, and I had forgotten that we were using a worker thread in GS, so I have to work around this a bit.)

I have the solution to the Toast issue about 75% in-place, but I need to do a couple more things and then test it before I call it good to go and move on to MM. I had honestly been dreading the error recovery stuff, but once I traced through GS, it was actually very easy. Not only that, but I made some passing improvements to the code as I went along! MM is a bit more work to trace, but I already did a preliminary run-through, so I should be able to tackle this in the coming week 🙂

Testing Network Connection For Android Phones

After deciding to take a hold off of OpenSocial Metagenomics and the headaches that came along with it, I began to finally sit down and figure out how Josh and I could test network connection with our Android apps. Although we attempted to find the solution a few weeks into the development of GenomeSearch, we didn’t find anything that worked. But with a new determination to produce some results I discovered the solution using the NetworkInfo class and ConnectivityManager class that Android supplies. Here is the code for a test application I wrote which displays text on the screen saying whether there is a connection via wifi or phone service provider (3g):

public void onCreate(Bundle savedInstanceState) {

TextView tv = new TextView(this);
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

if ( cm.getNetworkInfo(cm.TYPE_MOBILE).isConnectedOrConnecting() ||
cm.getNetworkInfo(cm.TYPE_WIFI).isConnectedOrConnecting() )
tv.setText("Network available!");
tv.setText("No network available!");

Now we can implement this code into our applications to check and ensure users have network connection before performing any actions that require internet connection.


MM Gets Major Upgrade Thanks to OpenIntents!

Before I show you cool things, you’re probably wondering “what the heck is OpenIntents, Josh?” Well, OpenIntents is a pile of awesome pieces of code that work independently as useful software, but are also a great resource to tap for other projects. In my case, Mobile Metagenomics has been sitting around with a broken “Browse” button since the first day I made the layout. I knew that there were a handful of open source file browsers out there that I could use, but none of them seemed to work for me.

Today I tried pulling down the OpenIntents source directly from their svn repository, and it fixed all of my issues! The final result? When you click browse, this happens:


Thanks, OpenIntents!