在一個發佈方法中插入數據到另一個數據庫中的數據庫執行更新SQLite拋出異常,我需要暫停和恢復線程。我的計劃是運行一種方法來查詢我的數據庫,以免造成錯誤。Android應用中的暫停計時器
我的計時器,
cron = new Timer();
cron.schedule(scanTask = new TimerTask() {
@Override
public void run() {
startService(new Intent(getBaseContext(), CronPush.class));
}
}, 0, 30000);
@Override
protected Void doInBackground(Void... arg0) {
cron.cancel();
Sincronizacion s = new Sincronizacion();
s.sincronizarBD(MenuEvento.this, codigoEvento);
resume();
return null;
}
public void resume() {
cron = new Timer();
cron.schedule(scanTask = new TimerTask() {
@Override
public void run() {
startService(new Intent(getBaseContext(), CronPush.class));
}
}, 0, 30000);
}
03-27 23:19:49.520: E/AndroidRuntime(4603): FATAL EXCEPTION: AsyncTask #3
03-27 23:19:49.520:E/AndroidRuntime(4603):了java.lang.RuntimeException:執行doInBackground() 03-27 23發生錯誤: 19:49.520:E/AndroidRuntime(4603):at android.os.AsyncTask $ 3.done(AsyncTask.java:299) 03-27 23:19:49.520:E/AndroidRuntime(4603):在java.util.concurrent .FutureTask.finishCompletion(FutureTask.java:352) 03-27 23:19:49.520:E/AndroidRuntime(4603):at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 03-27 23 :19:49.520:E/AndroidRuntime(4603):在java.util.concurrent.Future Task.run(FutureTask.java:239) 03-27 23:19:49.520:E/AndroidRuntime(4603):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 03-27 23: 19:49.520:E/AndroidRuntime(4603):在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:573) 03-27 23:19:49.520:E/AndroidRuntime(4603):在java。 lang.thread.run(Thread.java:856) 03-27 23:19:49.520:E/AndroidRuntime(4603):引起:java.lang.IllegalStateException:TimerTask已安排 03-27 23:19: 49.520:E/AndroidRuntime(4603):在java.util.Timer.scheduleImpl(Timer.java:572) 03-27 23:19:49.520:E/AndroidRuntime(4603):在java.util.Timer.schedule Timer.java:481) 03-27 23:19:49.520:E/AndroidRuntime(4603):at com.androidaz.scanner.MenuEvento.resume(MenuEvento.java :266) 03-27 23:19:49.520:E/AndroidRuntime(4603):at com.androidaz.scanner.MenuEvento $ sincronizarBD.doInBackground(MenuEvento.java:216) 03-27 23:19:49.520:E/AndroidRuntime(4603):at com.androidaz.scanner.MenuEvento $ sincronizarBD.doInBackground(MenuEvento.java:1) 03-27 23:19:49.520:E/AndroidRuntime(4603):at android.os.AsyncTask $ 2。調用(AsyncTask.java:287) 03-27 23:19:49.520:E/AndroidRuntime(4603):在java.util.concurrent.FutureTask.run(FutureTask.java:234)
編輯POST並顯示錯誤信息,讓我按照你說的去做,看看你能否幫助我。 – Nico1991
提到的錯誤,請加我的帖子。 – Nico1991
編輯,嘗試新版本 –