How can i pass an object to a new thread generated anonymously in a button listener

Posted by WaterBoy on Stack Overflow See other posts from Stack Overflow or by WaterBoy
Published on 2012-07-11T03:00:09Z Indexed on 2012/07/11 3:15 UTC
Read the original article Hit count: 167

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about java

Related posts about android