已經創建了一個IntentService
,在我創建了一個靜態塊中,我做了一些網絡相關的工作,在其上給NetworkOnMainThreadException
: 代碼樣子:靜態塊拋出NetworkOnMainThreadException
public class XService extends IntentService {
static {
//Net related work
//on executing this gives NetworkOnMainThreadException
}
@Override
protected void onHandleIntent(Intent intent) {
//Doing my work here
}
}
throw NetworkOnMainThreadException
IntentSrevice
如何在單獨的線程上運行?
請幫助和提前致謝。
只有onHandleIntent()回調函數在後臺線程上運行。 – Luksprog