I am developing an application in which i have implement the service.But when i exit from my application, service stops (but onDestroy()
is never called) and then starts again (OnCreate()
called).
Actually,I dont want to stop service once it is created regardless the state of application.
As service onCreate()
is getting called again,service looses the previous processed data.I have tried START_STICKY
but no luck.
so, How can i keep my service running?
here is my service code,
public class ddservice extends Service{
public void onCreate() {
super.onCreate();
Log.e("dservice", "onCreate");
/*here i am processing some important data in
background thread*/
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e("ddservice", "onDestroy");
}
@Override
public void onStart(Intent intent, int startid) {
super.onStart(intent, startid);
Log.e("ddservice", "onStart");
}
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.e("ddservice", "onStartCommand");
return START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}//service class ends here
And i am starting this service from mainActivity as,
startService(new Intent(this, ddservice.class));