Reputation: 522
I want to use Service
in such way: first I start the service using startService()
method. OnStartCommand()
method returns START_REDELIVER_INTENT
. Then (immediately or not) I bind to this service.
1) Can I be sure that the onStartCommand()
is called on the service before calling onBind()
?
2) When service got killed and I bind to it - will it be first restarted with the last delivered Intent (due to START_REDELIVER_INTENT
flag) before calling onBind()
?
Upvotes: 1
Views: 893
Reputation: 11
onStartCommand()
should be called whenever the activity is started when it is started using startService
or if it isn't running and it is started when onBind()
is called but onStartCommand()
isn't called.
If you return START_REDELIVER_INTENT
the service is scheduled for restart as soon as it can be started again.
If you only want the service to run when you are interacting with it if you only use onBind()
and don't use startService()
then the service will be started if necessary and will be destroyed when you unBind()
.
See http://developer.android.com/reference/android/app/Service.html for lots of good information about using services.
Upvotes: 1