Is it possible to prevent the Service (startForground) from killing the OS?
Not. This is Android that decides which process to stop when. The only way is to make it βless attractive to stopβ by reducing the amount of memory it consumes.
Save memory. Put the service in your very small process. So the Android server can kill the main process for memory recovery, and your service can continue to work. Maintain a tiny service code by passing settings and settings with the intention of using the service.
Note: the tiny service must be a foreground service, that is, it should show an icon in the status bar.
process manifest
<service android:name="com.gosylvester.bestrides.ServiceLocationRecorder" android:process=":bestRidesService" > </service> </application>
Go to settings with the intention to use the service. Just restart the service to change the settings.
@Override public int onStartCommand(Intent intent, int flags, int startId) { boolean isTrackerMarker = SettingMarker.TRACKER_MARKER_DEFAULT; if (intent != null) {
source share