IntentService 空構造函數,InstantiationException(實例化異常),java NIO

IntentService 是繼承自 Service 並處理異步請求的一個類,在 IntentService 內有一個工作線程來處理耗時操作,當任務執行完後,IntentService 會自動停止,不需要我們去手動結束。如果在短時間內(Service沒有自動調用stopService)啓動 IntentService 多次,那麼每一個耗時操作會以工作隊列的方式在 IntentService 的 onHandleIntent 回調方法中執行,依次去執行,執行完自動結束。
 

報錯:                   Caused by: java.lang.InstantiationException: TestIntentServer has no zero argument constructor

原因就是由於構造函數問題有參數解決:

 IntentService 的構造函數 string 什麼用:

* @param name Used to name the worker thread, important only for debugging.

用於命名工作線程,僅對調試很重要。

 

 

java NIO

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章