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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:32:31+00:00 2026-05-18T20:32:31+00:00

When my activity is started it creates a service that acts as a server.

  • 0

When my activity is started it creates a service that acts as a server. The server receives raw data from my python script on my desktop. The Service creates and maintains DataManagers that handle all the data from my python script in a hash map keyed to the DM’s name. At any given time I need an activity to bind to the service request some data from the service and process, when the activity pauses, stops or is destroyed it will unbind.

I believe I have the binding correct, but when I start the service the passed ServiceConnection is always returned null. Any idea’s whats going on? my code was stolen directly from the RemoteService class from Android
Thanks
~Aedon

{Code addendum}

The HomeScreen Activity that binds to the PublicService

@Override public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    doBindService();
    setContentView(R.layout.homescreen);
    initView();
}

public void initView() {
    workbenchs = (Gallery)findViewById(R.id.workbenchs);
    workbenchs.setMinimumHeight(h/4);
    workbenchs.setAdapter(new WorkBenchAdapter(this));
    workbenchs.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            Intent it = new Intent(HomeScreen.this, Controller.class);
            it.putExtra("workbench", arg2);
            startActivity(it);
        }
    });
}

 // Gallery Adapter

public class WorkBenchAdapter extends BaseAdapter {
    public WorkBenchAdapter(Context c) {   }
    public int getCount() {return mBoundService.getNumBenchs();}
    public Object getItem(int position) {return position;}
    public long getItemId(int position) {return position;}

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView i = new ImageView(HomeScreen.this);
    i.setImageBitmap(mBoundService.getWorkbench(position).toBitmap());
        i.setLayoutParams(new Gallery.LayoutParams(w/4, h/4));
        return i;
    }
}


 // Service Necessities

public boolean mIsBound = false;
private PublicService mBoundService;
private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service) {
        mBoundService = ((PublicService.LocalBinder)service).getService();
    }

    public void onServiceDisconnected(ComponentName className) {
        mBoundService = null;
    }
};

void doBindService() {
    Log.d(TAG, "Binding...");
    bindService(new Intent(this, PublicService.class), mConnection, Context.BIND_AUTO_CREATE);
    mIsBound = true;
    Log.d(TAG, "Bound.");
}

void doUnbindService() {
    if (mIsBound) {
        Log.d(TAG, "Unbinding...");
        unbindService(mConnection);
        mIsBound = false;
        Log.d(TAG, "Unbound."); 
    }
}

My problem comes from the Workbench adapter. When the adapter is created it call get count (which starts as 0), but it keeps saying that the mBoundService is null. I have tried starting the service before binding and that changes nothing…

  • 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-18T20:32:31+00:00Added an answer on May 18, 2026 at 8:32 pm

    Did you specify the service tag in your manifest?

    In <application> you need to specify the service like this <service android:name="namespace.ServiceName"/>

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

Sidebar

Related Questions

When my activity is started it creates a service that acts as a server.
I have service with thread, From activity I am calling start service(from Activity::onDestroy()) and
We needed a location service for our app that was available from anyplace. We
I have an activity that has a TabHost containing a set of TabSpecs each
i have created a workflow activity that do give the item creater of a
I need to generate a list of activity from multiple tables in order of
I have a web-based application that notifies users of activity on the site via
I can find a way to send parameters to my activity from my notification.
I wrote an android program that: has a main activity for UI, and it
So, Here is my scenario: I have two activity and one service --> all

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.