我想在 Timer 线程中触发 AsynTask,我收到以下错误。
java.lang.ExceptionInInitializerError 原因:java.lang.RuntimeException:无法在未调用 Looper.prepare() 的线程内创建处理程序
有没有可能???这是我的代码
networkTimer = new Timer();
networkTimer.schedule(new TimerTask() {
int counter = 1;
@Override
public void run() {
// TODO Auto-generated method stub
if(isNetworkAvailable()){
Log.d("Hey I got the Network","!!");
new GmailAsync().execute("");
networkTimer.cancel();
}else{
Log.d("Attempt","No:"+counter);
counter++;
if(counter == 6){
Log.d("Attempt","Finished");
networkTimer.cancel();
}
}
}
},0, 5000);