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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:44:18+00:00 2026-06-11T22:44:18+00:00

I have an android service, I bound it to an activity, and unbound on

  • 0

I have an android service, I bound it to an activity, and unbound on destroy. The problem is, it starts out of nothing when the application is closed, sometimes when I turn on the device, sometimes ramdomly, I know it starts ’cause of a toast message. Lets get to the code…

Activity onCreate

Intent intent = new Intent(this, Sincronizacao.class);
this.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
this.startService(intent);

The code for mConnection

private ServiceConnection mConnection = new ServiceConnection() {
    public void onServiceConnected(ComponentName className, IBinder service) {
        serviceBound = true;
        localBinder = (LocalBinder<Sincronizacao>) service;
    }
    public void onServiceDisconnected(ComponentName className) {
        serviceBound = false;
        localBinder = null;
    }
};

And on destroy

@Override
protected void onDestroy() {
    super.onDestroy();
    if (serviceBound && mConnection != null) {
        unbindService(mConnection);
    }
    Intent intent = new Intent(this, Sincronizacao.class);
    stopService(intent);
    localBinder = null;
}

In my service, onStartCommand is implemented, in there I start out a thread wich query a web service and insert data into a database, the thread has a while(true), I simply interrupt it onDestroy method of the service…

Edit:

Here’s the manifest line

android:name="com.company.package.service.Sincronizacao" />

I’m struggling in this bug for some time already, hope you can help me.

Thanks,

  • 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-11T22:44:19+00:00Added an answer on June 11, 2026 at 10:44 pm

    I was able to solve the problem… Within the service, I moved the code from onStartCommand to onBind. I’ve had no problems since, I just use the service on a bidden state.

    Also, previously I was stopping the Thread inside the service with thread.interrupt(), now I’m using a flag in the while, and setting it to false on onUnbind and onDestroy.

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

Sidebar

Related Questions

i have a problem with binding a service to an activity in Android. The
I have an Android service, created in OnCreate of first Activity of the application
I have a peculiar problem , i have an android service which starts on
I have an android recurring service running in background, no Activity running in front
I have developed a Service for Android that starts when BOOT_COMPLETED is received.It works
I have a Web Service and an Android application that uses this web service.
I have a service bound to an activity. The activity is a ListView of
I have android application and service that runs in separate process. Application and service
I have an Android application that is binding to a persistent service (once started
I have a service bound to an activity. The service will access a JSON

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.