bob jeffer
bob jeffer

Reputation: 25

if Activity finish then Service also finish or not?

I am newbie please help me and clarify that if Activity finish then Service also finish or not? for example if activity start Services and then call to second Activity and finish itself then service also finish or remain? My secinds Question is Start services on splash Activity is good or not?

Upvotes: 0

Views: 404

Answers (2)

s.d
s.d

Reputation: 29436

Service finish depends on how Service is started and what does it do.

If a Service is a bound service, that is started via bindService(), then after all users of the service have called unbindService(), then the service is stopped.

Also, inside the service the value returned from onStartCommand() can determine if service would be restored by system if terminated or not.

Finally, a service an explicitly call stopSelf() to shutdown itself.

Read more in documentation here: https://developer.android.com/reference/android/app/Service.html#ServiceLifecycle

Upvotes: 1

Sascha Kolberg
Sascha Kolberg

Reputation: 7162

Services run independently of the place where you start them. So

  1. No a service won't stop just because the starting activity finishes
  2. An activity is as good a place to start a service as any place that has a android.content.Context.

Upvotes: 0

Related Questions