0
我從MainActivity網絡內服務
調用DBSync服務startService(new Intent(this, DBSync.class));
在線程主線程異常
的DBSync服務包含
public class DBSync extends Service {
Thread readThread;
int var1,var2;
@Override
public void onCreate() {
readThread = new Thread(new Runnable() {
@Override
public void run() {
try{
// My code which uses network,JSON and DBUpdation
} catch(Exception e){
}
}
});
readThread.run();
}
}
在清單
<service android:name=".DBSync" />
但它表明網絡主線程異常。
java.lang.RuntimeException: Unable to create service com.package.DBSync: android.os.NetworkOnMainThreadException