Android bound service, what happen when activity unbound it?

拜拜、爱过 提交于 2019-12-10 21:03:39

问题


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.

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/6830812/android-bound-service-what-happen-when-activity-unbound-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!