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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:33:42+00:00 2026-05-29T09:33:42+00:00

I am not certain how to resolve this, but in one Activity I call

  • 0

I am not certain how to resolve this, but in one Activity I call startService, and then immediately call to start the next Activity.

This works, the service starts, and begins to process the data as expected.

I go to the next Activity, and in onResume I call the AsyncTask to bind the service.

So, the basic flow is that I call the AsyncTask, the bindService returns false, so mConnection is never called.

So, the problem is why is bindService returning false?

The reason I put the binding in an AsyncTask is that I had the thread sleep for 10 seconds before binding to see if the service needed to start up first.

I also started the service inside this activity, first, in the onCreate method, and so waited 10 seconds, but bindService still returns false.

private class BindServiceTask extends AsyncTask<Void, Void, Boolean> {
    protected Boolean doInBackground(Void... params) {
        return bindService(
                new Intent(IMyCallback.class.getName()),
                mConnection, Context.BIND_AUTO_CREATE);
    }
    protected void onPostExecute(Boolean b) {
        if (b) {
            Log.i(TAG, "onResume - binding succeeded");
            Toast.makeText(mContext, "Bound to service succeeded",
                    Toast.LENGTH_LONG).show();
        } else {
            Log.i(TAG, "onResume - binding failed");
            Toast.makeText(mContext, "Bound to service failed",
                    Toast.LENGTH_LONG).show();
        }
    }
}
private IMyCallback mCallback = new IMyCallback.Stub() {
    @Override
    public void dataChanged(double[] info) throws RemoteException {
        mHandler.sendMessage(mHandler.obtainMessage(LOCATION_MSG, info));
    }
};
IMyService mIRemoteService;
private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service) {
        Log.i(TAG, "onServiceConnected");
        mIRemoteService = IMyService.Stub.asInterface(service);
        try {
            Log.i(TAG, "registering callback");
            mIRemoteService.registerCallback(mCallback);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString());
        }
    }

    public void onServiceDisconnected(ComponentName className) {
        Log.e(TAG, "Service has unexpectedly disconnected");
        mIRemoteService = null;
    }
};
  • 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-29T09:33:42+00:00Added an answer on May 29, 2026 at 9:33 am

    When you call bindService() it won’t necessarily return your service connection or API to access the service. It happens asynchronously. You need a callback like this:

    class PictureUploadQueueServiceConnection implements ServiceConnection {
        public void onServiceConnected(ComponentName name, IBinder service){
            Log.d(TAG, "PictureUpload Service Connected!");            
            pictureUploadQueueApi = PictureUploadQueueServiceApi.Stub.asInterface(service);       
        }
    
        public void onServiceDisconnected(ComponentName name){
            Log.d(TAG, "PictureUpload Service Connection Closed!");
            pictureUploadQueueApi = null;
        }
    };
    

    Your call to do the bind should look like this:

    getApplicationContext().bindService(new Intent("org.me.xxxx.PictureUploadQueueServiceApi"),
                            pictureUploadQueueServiceConnection,
                            Context.BIND_AUTO_CREATE
                    );
    

    Make sure in your service you are implementing the API Stub and returning an instance of it in your onBind() method:

    private PictureUploadQueueServiceApi.Stub api = new PictureUploadQueueServiceApi.Stub() {
        @Override
        public void queuePictureUpload(String remoteURI, String localURI, String target, String description, String callback) throws RemoteException {
            appendPictureUpload(remoteURI, localURI, target, description, callback);
        }
        @Override
        public boolean isEmpty() {
            return queue.size() == 0 ? true : false;
        };
    };
    
    @Override
    public IBinder onBind(Intent intent) {
        Log.d(TAG, "Bound Intent: " + intent);
        return api;
    }
    

    Lastly, to complete the example, the AIDL file for my example looks like this:

    interface PictureUploadQueueServiceApi {
    
            void queuePictureUpload(String remoteURI, String localURI, String target, String description, String callback);
    
            boolean isEmpty();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not certain if this will get much response due to the newness of Windows
I'm not certain how to explain this with the correct terms so maybe an
One of my projects works only with the Debug DLL and not with the
I'm not certain where the error is resulting (from silverlight, from wcf, something else...)
I've got a table structure I'm not really certain of how to create the
I would like my Core assembly to not expose a certain class and I
I am having an issue with implicit conversions not working under certain circumstances (higher
I need to define a Wix file component that may not exist in certain
Is a way to gather hardware information to uniquely identify a certain device (not
Not a competition, it is instead me trying to find why a certain regex

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.