开发者

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

开发者 https://www.devze.com 2023-01-03 03:38 出处:网络
I have an app that has a client Activity and 开发者_JS百科a long-running Service. The Service may be started by the alarm manager or by the Activity itself.

I have an app that has a client Activity and 开发者_JS百科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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号