4

I have created a android service. I start the service and stop the service using startService(intent) and stopService(intent).

My problem is that even i stop the service; it starts again without any explicit call to startService.

Any help appreciated

Sandeep
  • 667
  • 7
  • 25

1 Answers1

4

without proper code samples, this is difficult, but chances are that you have a bound services that is not unbound yet.

in case you dont have it bound, "this.stopSelf()" from within the service is one of the ways to do the trick:

public class BatchUploadGpsData extends Service {
    @Override
    public void onCreate() {
        Log.e(TAG, "here i am, rockin like a hurricane.   onCreate service");
        this.stopSelf();
    }

this is an actual code snippet from testing code that works on android 2.2 and up

tony gil
  • 9,424
  • 6
  • 76
  • 100
  • Wouldn't stopSelf() stop the service as soon as it is started? How can we let the service run then? – IgorGanapolsky Sep 15 '12 at 17:55
  • 2
    @IgorG. in this case it stops the service right after it executes its one and only line of code. imagine that there are thousands of lines of code BEFORE "this.StopSelf()". – tony gil Sep 16 '12 at 18:17