diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java index 6388c2fc5..519ffb4d3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ConfigureAlarms.java @@ -115,8 +115,18 @@ public class ConfigureAlarms extends AbstractGBActivity { DaoSession daoSession = db.getDaoSession(); Device device = DBHelper.getDevice(getGbDevice(), daoSession); User user = DBHelper.getUser(daoSession); - while (supportedNumAlarms > alarms.size()) { - alarms.add(createDefaultAlarm(device, user, alarms.size())); + for (int position = 0; position < supportedNumAlarms; position++) { + boolean found = false; + for (Alarm alarm : alarms) { + if (alarm.getPosition() == position) { + found = true; + break; + } + } + if (!found) { + LOG.info("adding missing alarm at position " + position); + alarms.add(position, createDefaultAlarm(device, user, position)); + } } } catch (Exception e) { LOG.error("Error accessing database", e);