3時間ごとにdb4oファイルを更新するサービスを使用しています:
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.d("Service", "Service started");
pref = new MyPreferences(getApplicationContext());
addNotificacion();//update notifications
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Looper.prepare();
Log.d(TAG, "updating...");
updateInService();
addNotificacion();
Log.d(TAG, "End of update");
}
}, 40000, 60000);
}
addNotificacion() メソッドに問題はありませんが、updateInService はサブジェクトの Exception をスローします。この方法では、db4o にアクセスし、http クライアントを使用して、AlarmManager のアラームを更新します。ただし、UI は変更しません。OnBootReceiver でサービスを開始します。
どうすれば問題を解決できますか?
前もって感謝します。
編集後:
追加後Looper.prepare();
、システムは最初の反復で OK を実行しますが、2 番目の反復ではインスタンス Looper.prepare();: java.lang.RuntimeException: Only one Looper may be created per thread で例外が発生しました
ありがとう!