在我的Android應用程序,我打電話都startService
和bindService
:我是否需要爲Android服務調用unbindService和stopService?
Intent intent = new Intent(this, MyService.class);
ServiceConnection conn = new ServiceConnection() { ... }
startService(intent)
bindService(intent, conn, BIND_AUTO_CREATE);
後來,我嘗試都unbindService and
stopService`:
unbindService(conn);
stopService(intent);
但是,我上調用unbindService
異常。如果我刪除了此通話,則該應用似乎可以通過stopService
通話正常運行。
我做錯了什麼?我認爲bindService
呼叫必須與unbindService
呼叫相關聯,並且startService
呼叫必須與stopService
呼叫相關聯。雖然這似乎並不是這種情況。
你有沒有想過這個?我遇到了同樣的事情,併爲我自己評論了unbindService(conn)。似乎沒問題,但就像你一樣,我的直覺說背景中的東西不會喜歡它。 – 2010-12-16 03:34:58