How to avoid this trouble? I want to call stopSelf() when uploading
finished. What constant I have to use to avoid this?
You can use IntentService which will automatically shutdown when task is completed.
As known Android system kills processes in case memory is low. And any
time my service can be killed till uploading wasn't finished?
You can use startForeground
service as
A started service can use the startForeground(int, Notification) API
to put the service in a foreground state, where the system considers
it to be something the user is actively aware of and thus not a
candidate for killing when low on memory
.
For
What constant I have to use to avoid this?
Use
START_STICKY
: to restart the service once Killed (intent will be null on restart)
START_REDELIVER_INTENT
: to restart the service once Killed and get the same intent back which was received first time
Note: very few devices does not follow the START_STICKY
and similar instructions.
Reference:
How to automatically restart a service even if user force close it?