I've just been googling various examples for implementing threading on some apps and I've come across a few approaches.
1. http://codinghard.wordpress.com/2009/05 ... messaging/
Purely uses handlers and messaging; whilst debugging I can see that a child thread is created and it persists - it is also a singular thread similar to (3).
2. I tried to put together an example of threading as runnable, http://pastie.org/pastes/1400971
You will see some notes of the issues I ran into. In this example, I noticed that the thread would quit on completion. On each click of the button it'd load a new parallel thread - a pipeline thread isn't maintained.
3. http://mindtherobot.com/blog/159/androi ... -handlers/
This works as advertised, once I ported all the code into a SDK 2.2 project. However, I'm looking for something more elegant such as your solution here (am still testing this, or to be more specific, getting my head around it!).
Questions:
A. is there a particularly best practice type approach here?
B. messaging vs. runnable - thoughts?
C. http://pastie.org/pastes/1400971 << any thoughts on this?
D. I took your approach, yanked out the Geo stuff just to see how the threading works and it's similar in operation to *my* messy approach that I took with runnable in (C) above.
Using java Syntax Highlighting
- public void onClick(View v) {
- Thread pipelineThread = new Thread() {
- public void run(){
- final String TAG = "pipelineThread";
- try {
- Log.i(TAG, "before sleep");
- Thread.sleep(1500); //just to show you that it works
- Log.i(TAG, "after sleep");
- } catch (Exception e) {
- // @todo: Show error message
- }
- showResults.sendEmptyMessage(0);
- }
- };
- pipelineThread.start();
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Thanks,
Mike
mike@bsodmike.com / @bsodmike on Twitter

