我正在从 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