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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:26:13+00:00 2026-05-16T15:26:13+00:00

I have a pretty simple local service that I’m trying to bind to my

  • 0

I have a pretty simple local service that I’m trying to bind to my activity. I worked through this yesterday with CommonsWare and he got me straightened out as I was having a difficult time getting the service to bind. It turns out that the reason I was having so much trouble was that I was trying to bind the service with:

bindService(new Intent(this, myService.class), mConnection, Context.BIND_AUTO_CREATE);

inside a void method that was being called after a button click.

private void doBindService() {
            bindService(new Intent(this, SimpleService.class), mConnection, Context.BIND_AUTO_CREATE);
            mIsBound = true;
        }

       private OnClickListener startListener = new OnClickListener() {
        public void onClick(View v){
            doBindService();
        }               
       };

when I moved my bindService() call to the onCreate method of the activity, it works fine. CommonsWare mentioned something about that call being asynchronous and I don’t know enough about android activity creation to know if that’s what my issue was or not. I do know that my onServiceConnection() was being called inside my ServiceConnection() when the button was being clicked, by my mBoundService would not work when I tried accessing members inside the service.

Can someone tell me why it doesn’t work inside the button click, but does work inside the onCreate()?

TIA

  • 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-16T15:26:13+00:00Added an answer on May 16, 2026 at 3:26 pm

    The this reference inside of doBindService is not the same in both instances. If called in onCreate it will be a reference to the Activity if called from the button click it will be a reference to the OnClickListener. Obviously you do not want your service bound to the buttons click listener.

    Try changing this to YOURACTIVITYNAME.this and see if that helps.

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

Sidebar

Related Questions

I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have a pretty simple problem. Basically I have an array called $list that
Pretty simple code but a weird situation... have a template with this snippet: {%
This problem's pretty simple- we have a Change Password screen, and on it, the
I have a windows service application that runs as Local System, and I want
I have a pretty simple setup for this unit test. I have a class
i have pretty simple simple question (i hope so). How do i change the
I have a pretty simple trigger: CREATE OR REPLACE FUNCTION f_log_datei() RETURNS TRIGGER AS
I have a pretty simple Linq to XML query: var q = from c

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.