【发布时间】:2011-03-24 01:38:53
【问题描述】:
在我的 Android 应用中,我同时调用 startService 和 bindService:
Intent intent = new Intent(this, MyService.class);
ServiceConnection conn = new ServiceConnection() { ... }
startService(intent)
bindService(intent, conn, BIND_AUTO_CREATE);
后来,我尝试了unbindService andstopService`:
unbindService(conn);
stopService(intent);
但是,我在调用 unbindService 时遇到异常。如果我删除此调用,该应用似乎可以通过stopService 调用正常运行。
我做错了吗?我认为bindService 调用必须与unbindService 调用相关联,startService 调用必须与stopService 调用相关联。不过,这里的情况似乎并非如此。
【问题讨论】:
-
你有没有想过这个问题?我遇到了同样的事情,并为自己注释掉了 unbindService(conn)。似乎工作正常,但就像你一样,我的直觉在后台说不喜欢它。