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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:45:24+00:00 2026-05-23T23:45:24+00:00

I am a noob learning Android via a book, i have a quick question.

  • 0

I am a noob learning Android via a book, i have a quick question. My book code is pretty simple and looks like this:

My handler:

 Handler handler=new Handler() { 
    @Override 
    public void handleMessage(Message msg) { 
      bar.incrementProgressBy(5); 
              } 
  }; 

My thread:

Thread background=new Thread(new Runnable() { 
          public void run() { 
            try { 
              for (int i=0;i<20 && isRunning.get();i++) { 
                Thread.sleep(1000); 
                handler.sendMessage(handler.obtainMessage()); 
              } 
            } 
            catch (Throwable t) { 
              // just end the background thread 
            } 
          } 
        }); 

My question is here:

handler.sendMessage(handler.obtainMessage());

What the heck is “handler.obtainMessage()” ?
Doing a mouse over in Eclipse gives me a message that sounds like gibberish.
What message is it trying to “obtain”?

  • 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-23T23:45:25+00:00Added an answer on May 23, 2026 at 11:45 pm

    As described in the docs, it obtains a message from the message pool instead of creating a new one. (you need to send a message to the handler anyway):

    Returns a new Message from the global message pool. More efficient
    than creating and allocating new instances. The retrieved message has
    its handler set to this instance (Message.target == this). If you
    don’t want that facility, just call Message.obtain() instead.

    I’ll try to elaborate:

    You send a message to the handler. The message is added to the handler’s thread queue and processed on the original thread. You need to send it a message, though you have nothing specific in the message that it uses (according to your handler code) so you just send an empty message, but instead of allocating a memory for a new message, the message is taken from the message pool, which is faster.

    Hope this makes things clearer.

    Regarding how to set a message with an int:

    Message m = new Message();
    Bundle b = new Bundle();
    b.putInt("what", 5); // for example
    m.setData(b);
    handler.sendMessage(m);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Scala, so this is probably pretty noob-irific. I want to have a
Noob question here, my basic setup looks like this: (function($) { $.fn.imageSlider = function(options)
Am a noob learning Android via a book and for threading I see there
Noob question. I have this situation where I have these objects: class Address {
I have a noob question but he, i'm learning :-) I'm making a form
I am a noob learning android and building a simple game at the same
Total noob here learning openGL and I don't have any code to post because
This is just an experienting/learning example. I'm an extreme functional noob. F# code to
In advance: sorry for the noob question but I'm learning Cocoa & Objective-C and
Noob question, apologies. I'm compiling Java in Windows Vista's command-line and have so many

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.