Tag Archives: Thread

The First Rule of Programming

If I were clever, I’d say that it is “you don’t talk about programming”. Since I’m not clever, I submit that the first rule of programming is “check to see if somebody else already figured it out”. The answer is yes at least 85% of the time, and usually that person did a better job than you would if you’re rushing towards a bigger and better goal. On that note, I found this cool thing today.

I’ve been thinking over approaches for dealing with the issue of MM getting onPause()’d, and have tried my hand at a few snippets of code so far. I still rather like my approach of the downloads happening in a service while the background thread deals with sorting results. I believe that Käppler‘s approach will save me a lot of time on coding my onResume()/onPause() and generally laying out the structure. I haven’t studied his code intesively enough yet, but it already looks much more promising than what I frantically hacked up last week on the subject.

So, next time you’re about to scratch-code something difficult, talk to Uncle Google and see if some helpful person already solved the problem for you! 🙂 …and that is all from me for the week, as I’m going on vacation. Enjoy the silence!

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

Multiple Background Threads in Android

One of the main things that came out of my Android tinkering today was knowledge of multi-threading. The threading technique used in GenomeSearch had ‘multiple’ threads as well (2), but the implementation was a bit lacking. Without going into too much detail, GenomeSearch has one (main) thread which manages the User Interface, and one background thread that blocks on network I/O. Unfortuantely, the implementation is such that if we had ever needed a third thread, we wouldn’t have been able to add it.

So, with a little help from this conversation on Android Beginners, I wrote up a little snippet to test running multiple background threads in addition to the main UI thread. You can find the code behind the cut (note that you will need to set up all of the other project files for this to work (layout, manifest, etc).

Continue reading