概述
http://blog.sina.com.cn/s/blog_749e806f0100yikk.html
开始代码如下:、
public void onCreate(Bundle b){
,最后找了好久,在一个外国网站上找到如下:
http://stackoverflow.com/questions/3792344/why-isnt-onserviceconnected-called
This is the designed behavior of all of these methods. For example,in the bindService(Intentservice, ServiceConnection conn, intflags)
The service will be considered required by the system only for aslong as the calling context exists. For example, if this Context isan Activity that is stopped, the service will not be required tocontinue running until the Activity is resumed.
For unbindService(ServiceConnection conn)
Disconnect from an application service. You will no longer receivecalls as the service is restarted, and the service is now allowedto stop at any time.
In the startService(Intentservice)
Using
startService()
overridesthe default service lifetime that is managed by bindService(Intent,ServiceConnection, int)
: it requires the service to remainrunning untilstopService(Intent)
iscalled, regardless of whether any clients are connected to it. Notethat calls to startService()
arenot nesting: no matter how many times you call startService()
,a single call tostopService(Intent)
willstop it.
也就是说:在绑定的的时候Context 不可以为空,在OnCreate中绑定,当然contexe没有完成啊!
所以就把代码转移到和服务链接器连接成功里面调用!
private ServiceConnection conn=new ServiceConnection(){
最后
以上就是幽默鞋垫为你收集整理的android service bindService onServiceConnected没有调用的全部内容,希望文章能够帮你解决android service bindService onServiceConnected没有调用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复