0
私はデータベースからアラームを設定する必要がある私のコードが動作していない小さなアプリケーションを作っています!私は1分間黒い画面を取得し、その後停止します アンドロイドで一度に複数のアラームを設定するにはどうすればいいですか?なぜ私のコードのバグでしょうか?アンドロイドのスレッドを使用してデータベースから一度に複数のアラームを設定する方法はありますか?
private void ringalarms(){
final Cursor data = myDB.getListContents();
final ExecutorService es = Executors.newCachedThreadPool();
ScheduledExecutorService scheduleTaskExecutor = Executors.newScheduledThreadPool(10);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
final Calendar calendar = Calendar.getInstance();
final Intent myIntent = new Intent(this.context, Alarm_Receiver.class);
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
// Do stuff here!
Log.d("i ammm heeere in runn", "yep iam here");
//display();
runOnUiThread(new Runnable() {
@Override
public void run() {
int hr,mt,iddata= 0;
while (true) {
data.moveToFirst();
while (!data.isAfterLast()) {
hr = Integer.parseInt(data.getString(0));
mt = Integer.parseInt(data.getString(1));
iddata = Integer.parseInt(data.getString(2));
calendar.set(Calendar.HOUR_OF_DAY, hr);
calendar.set(Calendar.MINUTE, mt);
myIntent.putExtra("extra", "yes");
//myIntent.putExtra("id", i);
pending_intent = PendingIntent.getBroadcast(Add_Alarm.this, iddata, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pending_intent);
data.moveToNext();
}
}
}
});
}
}, 0, 5, TimeUnit.SECONDS);
}
「UI」スレッドで無限ループを実行している可能性がありますか? –
実際に私は自分のデータベースをいつもチェックしたいのですがなぜ無限に使用したのですか – moha
あなたはすでに5秒ごとに実行される 'scheduleTaskExecutor'を使用しています。それだけであなたのデータベースをチェックするのに役立ちます。 –