2

I have a Service in my android application which stop only when quitting the application.

public class MyService extends Service {

    public MyService() {
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        try {
            if(intent != null){
                //......
            }
        } catch (Throwable e) {
        }
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //......
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }


}

This service calls its onCreate() method sometimes itself while running.When checking the state of service it is running but its functionalities does not work.I am stuck on this for many hours.What is the problem here?I tried onLowMemory() in this service.But not result.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Devu Soman
  • 2,246
  • 13
  • 36
  • 57

1 Answers1

0

If you return START_STICKY in the onStartCommand(), the Service gets created again if its killed by system (probably on a low memory condition). The same thing must have happened in your case and onCreate() got called.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sujith
  • 2,421
  • 2
  • 17
  • 26