I have an activity with two buttons, start and stop. If the user press the start button a service is created using Context.startService. And the stop button calls Context.stopService.
I want the stop button to be the only way to destroy the service. Now, if i end the activity using a task manager, the service is killed as well. Is there any way to avoid this?
EDIT: Also, i would like to know how a task manager (such as Advanced Task Manager Free) kills activities and services? Since none of my onDestroy() and such methods is called.
No. Also bear in mind the user can stop your service whenever they want through the Settings application built into Android.
See
ActivityManager#restartPackage(). Bear in mind that the behavior of this method may change in the future.