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 1011445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:14:08+00:00 2026-05-16T09:14:08+00:00

I’m really confused about this, but when I’m trigging a thread from my SurfaceView,

  • 0

I’m really confused about this, but when I’m trigging a thread from my SurfaceView, im sending a Handler with the constructor like this

private static Thread thread;

public SurfaceView(Context localContext) {
      //other stuff
      thread = new Thread(mySurfaceHolder, myEngine, this, new Handler());
      //other stuff
}

and in my thread-class I assign a Handler-object with the handler I sent from my view, like this:

    public Thread (SurfaceHolder lHolder,
    Engine lEngine,
    View lView,
    Handler lHandler){

    surfaceHolder = lHolder;
    engine = lEngine;
    view = lView;
    handler = lHandler;

}

So what does this Handler do? I never use it in my thread-class in any ways, so why are the examples on the web still showing me that I should send a handler with the constructor?
I can’t see the connection.

  • 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-05-16T09:14:08+00:00Added an answer on May 16, 2026 at 9:14 am

    I assume in your code you are extending Thread, because there is no constructor taking a handler for the Thread class. The handler is used to communicate back to the UI thread, as the Android threading model requires UI operations to be performed on a special dedicated thread.

    When creating a new thread, the code is executed in a background thread, and thus UI-operations are unsafe. If you do not need to do anything UI-related, you can remove the handler.

    Since Android API 3, there is AsyncTask, which makes communication between background and UI easier and alleviates the need to use a handler.

    Examples:

    • For an example of using a Handler,
      see this.
    • See Painless
      Threading
      as well, which contains links to sample projects using threading.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.