Reputation: 18754
I have a thread inside an invokeLater method in Blackberry like:
startButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field arg0, int arg1) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Thread thread = new Thread(){
public void run() {
uploadFile();
}
};
thread.start();
}
});
}
I have a thread because I want to run that function in the background and want to be able to do other stuff while its doing its job. What I am wondering is if this is a good approach. Do I really need the invokeLater in this case ?
Upvotes: 1
Views: 376
Reputation: 8920
Short answer: no.
Long answer:
InvokeLater puts the Runnable on the event queue so that, in time, when the event loop sees the Runnable it will execute it on the event thread. Since you are calling invokeLater in the fieldChanged method of a FieldChangeListener, you are calling it from the event thread. Unless what you want to do is delay the start of your thread to some unknown later time then no you don't need to use invokeLater.
Upvotes: 2