Sorry about a previous identical discussion. My browser posted my
message before I was done.
I've been trying to do my heavy processing in a background thread to
keep my UI responsive, as instructed, but whatever I seem to try it
doesn't seem to be put in a separate thread. (I only have the emulator
to develop on, at the moment.)
I've tried several different ways; here's how my code looks at the
moment.
Here's my button press, where I call the thread:
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
pd = ProgressDialog.show(gui, "Working...", "Calculating");
messageHandler.post(calcThread);
}
});
Here's my calcThread, as a member variable:
private Thread calcThread = new Thread(){
@Override
public void run() {
super.run();
heavyCalculations();
//Send update to the main thread
messageHandler.sendEmptyMessage(0);
}
};
And the message handler:
// Instantiating the Handler associated with the main thread.
private Handler messageHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
after_execute();
}
};
I've also tried starting my thread with just calcThread.start() and
then at the end of my calcThread calling a function from my class to
the UI work at the end of my thread. Neither way seemed to put my
worker thread on a separate thread. I tried pressing buttons after
executing and the UI is unresponsive until the calculations are done.
Anybody notice what I'm doing wrong? Or perhaps this is a problem with
the emulator and not my code?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---