0

I hava a simple service with data - ArrayList < MyObject > , when I close the app - service is restarted, called onCreate method and data is losing. This is my onStartCommand method:

public int onStartCommand(Intent intent, int flags, int startId) {
    .....
    return START_STICKY;
}

Service start in Application class

  Intent serviceIntent = new Intent(this, ChatNotificationService.class);
  startService(serviceIntent);

I not called stopService method.

I need after closing the application, the service continued to work and the data saved in it. How I can do it?

In activity:

@Override
protected void onCreate() {
    super.onCreate();
    bindService(serviceIntent, sConn, 0);
}

@Override
public void onDestroy(){
    super.onDestroy();
    chatNotificationService.closeConnections();
    unbindService(sConn);
}
Dmitriy Puchkov
  • 1,530
  • 17
  • 41
  • Please post the activity's onCreate(), onStart(), onPause() and onStop() methods – SME_Dev Oct 20 '14 at 10:25
  • 1
    Have you read http://stackoverflow.com/questions/15452935/android-background-service-is-restarting-when-application-is-killed or http://stackoverflow.com/questions/20073546/sticky-service-restarts-after-application-close ? – Dhaval Patel Oct 20 '14 at 10:27
  • yes, it not work for me.Apparently the only way to save and retrieve them in the method onCreate. – Dmitriy Puchkov Oct 20 '14 at 10:36

0 Answers0