Android的绑定服务,活动时解开它发生什么? [英] Android bound service, what happen when activity unbound it?

查看:161
本文介绍了Android的绑定服务,活动时解开它发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以绑定服务和调用服务的方法我的主要活动。

I have my main activity that can bind a service and call a service method.

的服务方法启动一个线程(在服务),该下载的数据,并将它们存储在数据库。在下载结束时,线程可以重新启动。

The service method start a thread (in service) that download data and store them in db. At the end of download the thread can be restarted.

什么发生,如果活动调用unbindService(即的onPause)?服务被破坏和线程停止或服务被破坏,当所有任务的结束?

What happen if activity call unbindService (i.e. in onPause)? Service is destroyed and thread stopped or the service is destroyed when all task end?

推荐答案

如果该服务被previously使用 startService()方法启动,然后绑定到它之后,解除该服务将继续运行。

If the service was previously started using the startService() method and then bound to it, after unbind the service will continue running.

如果你只是使用启动该​​服务 bindService()创造,如果它没有后解除绑定运行的服务,如果没有其他活动绑定到服务,该服务将停止。

If you just started the service by using bindService() which creates the service if it is not running after unbind if no other Activity is bound to the service, the service will stop.

这篇关于Android的绑定服务,活动时解开它发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆