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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:58:06+00:00 2026-06-06T23:58:06+00:00

In android.os.Message, there are a lot of fields for another thread to identify what

  • 0

In android.os.Message, there are a lot of fields for another thread to identify what to do after receiving a message.

public int what;
public int arg1; 
public int arg2;

However, if we change the value in the fields after putting the message into the message queue, it’d affect the way the receiver thread handles the message.

Why doesn’t Android team make android.os.Message immutable?
I think it’ll prevent the Android developers to make mistakes.

Isn’t it a better design to make it immutable?

  • 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-06T23:58:07+00:00Added an answer on June 6, 2026 at 11:58 pm

    I have no exact answer for first question (only android team has one). Looks like, it’s related to some memory/performance considerations. Generally, creation of objects are quite expensive, so, Android suggests :

    the best way to get one of these is to call Message.obtain() or one of the Handler.obtainMessage() methods, which will pull them from a pool of recycled objects.

    If You follow android reference and use Message.obtain(), you won’t spent time and memory on creation new Message objects, but will re-use existing ones from the ‘message query’. I believe Message was made mutable, because Android is for mobile systems with restricted resources (not sure if it’s valid point today, but it was some years ago).

    The same time immutable objects have many advantages. Check out Effective Java Item 15: Minimize mutability for more details. Main reasons for using immutable classes are:

    • Immutable objects are simple;
    • Immutable objects are inherently thread-safe; they require no synchronization;
    • Immutable objects can be shared freely, even you can share their internals (whose are finals usually);
    • It’s easier to build other objects with immutable ones;

    Effective Java mentions only single disadvantage of immutable classes: they require a separate object for each distinct value.

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

Sidebar

Related Questions

I'm setting a TextView with the id @android:id/empty to display a message when there
Is there any way to modify the generic Android Exception message The application ...
I got the Error message in Android below, it is send by PHP server
When i am deleting a SMS message from android system, with this code: context.getContentResolver().delete(
My android application takes sms messages from a BroadcastReceiver and copies the message into
to send a message in my application in android i have used the following
I am making an android game that should display a message that you have
I'm using the package android.telephony.SmsManager to send an SMS message from within my application,
I want to call a method say success(message) of javascript from android activity. I
Is there a way to access and query the android SMS/MMS log? To clarify,

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.