所以我试图同时执行两个线程睡眠。
线程1应该每20秒执行一次,同时线程2也应该每10秒执行一次。问题在线程2中我必须调用AsyncTask并且AsyncTask每20秒而不是10执行一次。 / p>
new Thread(new Runnable() {
@Override
public void run() {
while (check) {
try {
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (nw.isConnectingToInternet() ==false) {
//dosometask
}
}
});
Thread.sleep(20000);
} catch (Exception e) {
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Log.d("TAG", "10 sec over");
while (check) {
try {
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
l1 = new Location_Provider(MainActivity.this);
Locationcheck lchk = new Locationcheck();
lchk.execute();
}
});
Thread.sleep(10000);
} catch (Exception e) {
}
}
}
}).start();
}
我哪里错了?请告诉我..