0

I'm working on an android project where I've to start a service every time the app is closed. That works correctly. The problem is the following: if the app is killed while is in second plane, the onDestroy method is performed but the service never starts. Here is the case:

  • Open the app
  • Pass it to second plane (by minimizing)
  • From the list of app that are in second plane, I close my app using the option "Remove from list"

On the onDestroy method I have another method that initializes the services and the services is configured with return Service.START_STICKY;

I've seen several questions (for example: START_STICKY and START_NOT_STICKY, Continue service when app is killed , Starting a service from application class) but they have not worked.

Thanks

Community
  • 1
  • 1
AlphaDeveloper
  • 539
  • 8
  • 23
  • You cannot reliably detect when an app is killed. You can detect when it goes to the background, i.e. `onPause`. – Simas May 22 '15 at 19:17
  • But when I kill the app in the way that I showed, I can see from the log that the OnDestroy method from the main activity is being called – AlphaDeveloper May 22 '15 at 19:31
  • [onDestroy documentation.](http://developer.android.com/reference/android/app/Activity.html#onDestroy()) – Simas May 22 '15 at 19:33
  • Bullet and code formatting – antonio May 25 '15 at 16:41
  • Well, finally I decided to start the service every time that the application pass to second plane and stop it when is resumed. Thanks @Simas for your responses. – AlphaDeveloper May 27 '15 at 14:07

0 Answers0