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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:57:27+00:00 2026-06-14T09:57:27+00:00

I add few key-value pairs to a hashmap. After I add key-value pair, when

  • 0

I add few key-value pairs to a hashmap.

After I add key-value pair, when I print the size of hashmap, I get the size as 1. When I print the value at another place(after adding value to key-hashmap), I get the size of hashmap as zero. I do not remove the value added to this hashmap from this class or any other external classes. Then , how the hashmap size becomes zero? Can someone please explain?

Any help is appreciated.

Code here:

private HashMap <Context,BLEEventListeners> mHashMapCallbacks = new HashMap<Context,BLEEventListeners>();
public void startTimeServer(BLEEventListeners eventListener,Context context) {
    mHashMapCallbacks.put(context, eventListener);
    Log.d(TAG,"****Inside startTimeServer,mHashMapCallbacks size: " +mHashMapCallbacks.size());// I get 1 as size
    Intent cmn_intent = new Intent(IServerCommon.class.getName());
    Intent time_intent = new Intent(ITimeServer.class.getName());
    mContext.bindService(time_intent, time_connection, Context.BIND_AUTO_CREATE);
    mContext.bindService(cmn_intent, cmn_connection, Context.BIND_AUTO_CREATE);
}

private ICommonResultCallback callback = new ICommonResultCallback.Stub() {
    public void receiveMessage(Bundle value) throws RemoteException {
        Log.d(TAG,"****Inside connected,mHashMapCallbacks size: "   +mHashMapCallbacks.size());// I get 0 as size
 }
        }
  • 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-14T09:57:28+00:00Added an answer on June 14, 2026 at 9:57 am

    ICommonResultCallback() looks like a callback function. If it is, then hashmap will be initialized again when this function is called. This is because a new Instance of you class is created for call back also.

    You can verify this by using making hashmap “static”. It should then retain the value.

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

Sidebar

Related Questions

I'm using jQuery to dynamically add new divs containing a few fields. I'm adding
I want to cache 10.000+ key/value pairs (both strings) and started thinking which .NET
I need to add key and value to an existing array and don't seem
I wanna sort a collection of dates value pair. My key is Date and
I'm trying to add few contents to expander however, it throws following error <Expander
I have a website where I display student info. I want to add few
I have used hook_form_FORM_ID_alter( ) function to alter a menu_edit_menu form to add few
I want to add a few dynamic rows right in the middle of a
I am trying to add a few extra methods to a matrix type from
I have written a few Excel 2003/2007 add-ins using VSTO, and I usually end

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.