How to prevent app being killed in background?
Implement Foreground Service
in your app to increase the component priority in OS to lower the odds of its killing.
How to avoid system killing service when application/activity is killed
It is very important for me that the service doesn't get killed
Your processes can be killed at any time, for any reason, based on user activity (recent tasks list, a third-party task manager, "Force Stop" in Settings, etc.) or based on OS needs (system RAM is getting low). You cannot prevent this.
You can take some steps to minimize the odds of the OS deciding on its own to terminate your process, such as using startForeground()
on the service, but this does block the user from doing what the user wants with your app's process.
I'm displaying a window from that service so if the service stops then the window disappears.
Presumably, the user wants your window to disappear if the user is explicitly getting rid of your app via the recent tasks list, a task manager, etc. You are certainly welcome to advise users in your documentation of any negative effects that this will have.
You are also welcome to experiment with having that service be in a separate process. My understanding is that this will not help with the recent-tasks list on Android 4.4, though it might on earlier versions of Android. Whether this helps with third-party task managers probably depends on the manager, and this should not help with "Force Stop" from settings. It also means that you will have to deal with IPC, increased system RAM consumption while your main and service processes are both running, etc.
Related Topics
Gradle - Library Duplicates in Dependencies
How to Request Permissions from a Service in Android Marshmallow
How to Sign an Already Compiled APK
How to Prevent a Service from Being Killed by Os
Android Support Repo 46.0.0 with Android Studio 2.3
Creating a Preference Screen with Support (V21) Toolbar
Java.Lang.Illegalstateexception: Can Not Perform This Action After Onsaveinstancestate
Convert a Bitmap to Grayscale in Android
Service Not Available While Calling Geocoder.Getfromlocation()
Loading Existing .HTML File with Android Webview
How to Hide an Item from Recycler View on a Particular Condition
Using the Recyclerview with a Database
Android: Binding Data from a Database to a Checkbox in a Listview
How to Save Custom Arraylist on Android Screen Rotate
Using Asynctask to Load Images in Listview