Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:43:04+00:00 2026-06-07T09:43:04+00:00

I would like to pass an object (docket for printing) to a new thread

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:43:05+00:00Added an answer on June 7, 2026 at 9:43 am

    You could create your own Runnable class implementation:

        private class RunnableInstance implements Runnable {
    
        protected Docket docket;
    
        public void run() {
            //do your stuff with the docket
        }
    
        public void setDocket(Docket docket) {
            this.docket = docket;
        }
    
    }
    

    And then use it to create the thread

    public void onClick(View v) {
            RunnableInstance target = new RunnableInstance();
            target.setDocket(docketInstance);
            new Thread(target).start();
        }
    

    If you need to stick to an anonymous class you could do:

            public void onClick(View v) {
            final Docket docket = docketInstance;
            Runnable target = new Runnable(){
                public void run() {
                    // do your stuff with the docket
                    System.out.println(docket);
                }
            };
            new Thread(target).start();
    
        }
    

    But you have make sure you assign the instance to a final variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code which I would like to pass instances or classes interchangeably.
My problem here is that I would like to pass an object to a
I would like to pass certain data from an instance of an object to
I would like to pass a nested JavaScript object to my ASP.NET MVC Action
I would like to do the following: class A(object): pass a = A() a.__int__
I would like to pass the JSON object along with the view when I
Below is my Jquery code and I would like to pass Session paramater e.g.
Sometimes I would like to pass an immutable object to a method and change
I am using an ObjectDataSource and I would like to pass a custom object
I would like to pass data from a database column to another page via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.