Hi All,
Sorry my last question was not well formated. So I am deleting the content and re framing my question.
I liked @ChrisBunney answer to my question with an example to process image in another thread.
Here is proper code below
public class TestActivity extends ListActivity {
int count =0;
List<String> listString = null;
String[] mString = null;
private RefreshHandler mRedrawHandler = new RefreshHandler();
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
TestActivity.this.updateUI();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
private void updateUI(){
mRedrawHandler.sleep(1000);
listString.add("Test "+count++);
String[] mString = new String[listString.size()];
int i = 0;
for(String string : listString){
mString[i++]= string;
}
if(null != mString && mString.length>0)
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mString ));
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
listString = new LinkedList<String>();
updateUI();
}
}
What I intend to do is call UI update from another thread.
This will be the modification to my above code file.
private class HelperClass implements Runnable{
public void run() {
performSomeCalculation();
}
/*
* This code will populate the list as it is executed.
* As and when there is a new element in the list the UI is updated.
*/
public void performSomeCalculation(){
//update list String
updateUI();
}
/*
/*
*
* The new update onCreate method calling another thread that populates the UI thread
*
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
listString = new LinkedList<String>();
//updateUI();
Thread thread = new Thread(new HelperClass());
thread.start();
}
You can see in the above code I have created a HelperClass to perform some calculation , as and when there is ouput from the calculation thread it should update the UI thread.
I am working on it to make it work, if any one figures out plz update my post.
Thanks in advance.