Prevent Android Service From Being Killed By Os
Solution 1:
You cannot prevent your process from being killed. If OS decide to kill your processes you will be killed. Period.
The START_STICKY
will not do any magic os other answer incorrectly tells - docs about that value say:
If this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then leave it in the started state but don't retain this delivered intent. Later the system will try to re-create the service. Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after creating the new service instance; if there are not any pending start commands to be delivered to the service, it will be called with a null intent object, so you must take care to check for this.
Solution 2:
The best way to stop a service being killed by android is to create a persistant notification. This will make android keep the service alive at all costs because it displays something visible.
Post a Comment for "Prevent Android Service From Being Killed By Os"