Start service after app is killed or being killed

It's gotta be really silly question but i couldn't understand why activity onDestroy() method hasn't been called after killing app from recent tasks. I want to start service once app is being killed. Now i am not sure whether i could start service or not as onDestory() method never been called :-( ;

I killed the app from recent tasks. Here is how i start service

protected void onDestroy() {
    super.onDestroy();
    startService(new Intent(this, MyService.class));
}

Manifest declaration

<service
       android:name="com.example.activities.MyService"
       android:exported="true"
       android:process=":CustomService"/>

Update

it is said here that Activity's onDestroy method is not guarantee to be called every time and code shouldn't rely on this function. So ended up looking for other way round to meet my requirements

Answers


if you want call a Service when app closed , you can use OnStop(); method too.


Try the second solution in the following link and let me know the result.

onDestroy() not getting called while the activity is getting killed by the user?


I have not in your case but try to put startService before super.onDestroy


Need Your Help

How to display Primefaces dialog (dialog framework) as part of CustomExceptionHandler

jsf primefaces dialog custom-exceptions

I have a CustomExceptionHandler from which I want to display a modal dialog to get some information from the user, using Primefaces dialog framework.

Android using custom CursorAdapter with onContentChanged()

android cursor android-cursoradapter

I'm still trying to make a good code by using a cursorAdapter on a listView.