2012-09-18 28 views
-1

我有個奇怪的問題。我有一個服務啓動一個線程,在那個線程中有藍牙連接。這工作正常(它仍在開發中,但它的工作原理),我遇到了一個奇怪的問題:這是一個小的LogCat轉儲,應該說服務正在運行在這一點。安卓服務調用OnCreated運行時無意間

09-17 14:11:07.154: D/ReadXmlService(4552): The maximum numbers of event on the watch is reach (max: 5) 
09-17 14:11:07.154: D/MetaWatchReminderApp(4552): size of lastUpdatedEventsFromXml: 0 
09-17 14:11:07.154: D/MetaWatchReminderApp(4552): size of compareList: 4 
09-17 14:11:07.154: D/MetaWatchReminderApp(4552): compareList.tostring: [[email protected],  [email protected], [email protected], [email protected]] 
09-17 14:11:07.154: D/MetaWatchReminderApp(4552): lastUpdatedEventsFromXml.toString: [] 
09-17 14:11:07.154: D/MetaWatchReminderApp(4552): The list have been updated return true 
09-17 14:11:07.154: D/ReadXmlService(4552): new items in lastUpdatedEventsFromXml 
09-17 14:11:15.071: D/CalenderService(4552): onCreate'd 
09-17 14:11:25.091: D/ApacheBackground(4552): Background task 
09-17 14:11:25.091: D/ApacheBtService(4552): onCreate'd 
09-17 14:11:25.101: D/ApacheBtService(4552): state: connecting 
09-17 14:11:25.111: D/MetaWatchReminderApp(4552): getBluetoothMac D0:37:61:C3:34:B5 
09-17 14:11:25.151: D/BluetoothSocket(4552): create BluetoothSocket: type = 1, fd = -1, uuid = [00001101-0000-1000-8000-00805f9b34fb], port = -1 
09-17 14:11:25.261: D/ApacheBtService(4552): before connect 

服務正在運行,然後東西調用該函數onCreate方法,但它不會調用OnStartCommand功能,是否有任何人有任何想法爲什麼happent?

回答

0

查看您可能會在onStartCommand(Intent, int, int)返回的標誌。如果Android重新啓動您的服務調用onStartCommand(Intent, int, int)不保證一些標誌。

https://developer.android.com/reference/android/app/Service.html

+0

它也是我的第一個懷疑,但是當服務被殺害,它應該首先調用的onDestroy然後調用OnCreated agian? – user1613800

+0

僅當服務尚未啓動時才創建呼叫。我認爲,如果其他應用程序需要更多內存,那麼Android可能會關閉您的服務而無需調用Destroy。 – Nik

+0

謝謝,我認爲如果服務被殺,OnDestroy被調用。也許我可以閱讀更多關於這方面的鏈接?我應該重寫OnLowMemory函數並進行一些清理嗎? – user1613800