Hanoixan
Hanoixan

Reputation: 459

Service exiting after last client unbinds, even though startService() called beforehand?

I have an app that has a client Activity and a long-running Service. The Service may be started by the alarm manager or by the Activity itself.

The alarm intent calls startService(). The Activity calls startService, and then binds itself to the service so it can get information from it.

When I back-button out of the Activity, onDestroy() is called on the Activity, the Activity unbinds from the Service, and onDestroy() is called on the Service.

I was under the impression that if I called startService(), then the Service would stay around until stopService()/stopSelf() was called, no matter what clients have unbound from it.

Am I misunderstanding something?

Upvotes: 0

Views: 175

Answers (1)

drawnonward
drawnonward

Reputation: 53669

It partly depends on the SDK version you are using. In this Service Lifecycle reference, it says onStartCommand() must return START_STICKY for the behavior you want. Prior to API level 5, there was no onStartCommand and services were all sticky.

Upvotes: 1

Related Questions