I would like to pass an object (docket for printing) to a new thread which will print the docket. My code is:
private final Button.OnClickListener cmdPrintOnClickListener = new Button.OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
enableTestButton(false);
Looper.prepare();
doConnectionTest();
Looper.loop();
Looper.myLooper().quit();
}
}).start();
}
};
How do I pass the object to it?
Also – I need to generate the object in the UI thread, just before starting the new thread so where could I put this method (e.g. getDocketObject()) in relation to my code below
thanks,
anton
You could create your own Runnable class implementation:
And then use it to create the thread
If you need to stick to an anonymous class you could do:
But you have make sure you assign the instance to a final variable.