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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:57:59+00:00 2026-05-18T19:57:59+00:00

I have a service running in my Android application which contains a HashMap that

  • 0

I have a service running in my Android application which contains a HashMap that I would like to use in an Activity. So I bound the service to my activity and created a link between to two in order to use the data structure.

This is how I did it so far:

Activity (relevant code):

private ServiceConnection mConnection = new ServiceConnection() {

    public void onServiceConnected(ComponentName className, IBinder service) {
        imService = ((IMService.IMBinder) service).getService();            
    }

    public void onServiceDisconnected(ComponentName className) {
        imService = null;
        Toast.makeText(ViewFlipperTest.this,
                R.string.local_service_stopped, Toast.LENGTH_SHORT).show();
    }
};


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    bindService(new Intent(ViewFlipperTest.this, IMService.class),
            mConnection, Context.BIND_AUTO_CREATE); 
                 .
                 .
                 .
}
protected void onResume() {
    super.onResume();
    bindService(new Intent(ViewFlipperTest.this, IMService.class),
            mConnection, Context.BIND_AUTO_CREATE);     
}

private void getMap(ViewFlipper flipper2) {

    Map<Integer, internalChatObj> tempMap = imService.getMapwData();
   }

Service (relevant code):

public class IMService extends Service implements IAppManager{
                .
                .
                .

public Map getMapwData(){
    if(getNumberOpenChats()>0){
        return openChatMapwData;
    }
    else
        return null;

}
}

Each time I try and run the method getMap(), I get a null pointer. I even put a check to see if the imService was null and it was null each time. It seems that it is trying to obtain the data from the Service but the binding to the service is null, is that right? I have a check in the Service to send null if the map is empty, so that shouldn’t be a problem.

Any help?

Edit based on Will’s tips
New code

private ServiceConnection mConnection = new ServiceConnection() {

    public void onServiceConnected(ComponentName className, IBinder service) {
        imService = ((IMService.IMBinder) service).getService();
        dialog.dismiss();
    }

    public void onServiceDisconnected(ComponentName className) {
        imService = null;
        Toast.makeText(ViewFlipperTest.this,
                R.string.local_service_stopped, Toast.LENGTH_SHORT).show();
    }
};

public void onCreate(Bundle savedInstanceState) {
    dialog = ProgressDialog.show(getApplicationContext(), null,"Loading..", true, false);
}

Edit II

IMBinder Class (Seems standard, no?)

public class IMBinder extends Binder {
    public IAppManager getService() {
        return IMService.this;
    }
}

Is it necessary to have IMService.this instead of this?

  • 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-18T19:58:00+00:00Added an answer on May 18, 2026 at 7:58 pm

    It really seems like a timing issue; you shouldn’t call the getMap function unless you are certain the imService variable exists, which is after a call to onServiceConnected.

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

Sidebar

Related Questions

Hello I have an android application which has a service running. After 20 mins
I have a wcf application hosted in a windows service running a local windows
I have a windows service that runs various system monitoring operations. However, when running
I have an importer process which is running as a windows service (debug mode
I have a dotnet windows service that's currently hung, but running. Is there anyway
I'm testing an android application with a long running service. I'm using Eclipse and
I have a android webservice client application. I am trying to use the java
I have a WCF service running on the IIS with a ServiceHostFactory. It's running
I've got a WCF service up and running on a server. We have a
We have a remoting singleton server running in a separate windows service (let's call

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.