S.Drumble1 S.Drumble1 - 4 years ago 116
Android Question

Delete one alarm without messing everything up

I've created typical alarm clock. In SQLiteDatabase I keep data of all set alarms. Then, I retrieve that data, which looks like this : Tue, Sun, Sat; 7:30; loudness of alarm(it's just one row with 3 columns), Mon; 6:00(another row, still, 3 columns), with help of this data I set multiple and single alarms.

One really important fact is that I add(add to SQLiteDatabase and set in AlarmManager) one single or multiple alarm with an id that is provided by item count of a listView in which every alarm is shown. For example, I add new alarm and count of all previously set alarms is 6. So, this means that there are 6 alarms in listView and the next one should be with id of 6+1= 7.

So, how can I delete one alarm(or alarms, if there were set multiple alarms) without harming to all this "system"? So, everything would be on it's place.

P.s. if you didn't really understood how it works: add alarm to SQLiteDatabase, set alarm in AlarmManager, show count of alarms in ListView, when it's time for alarm - obtain loudness of alarm.

Thank you.

Answer Source

This is what helped me with the issue described above. Every new alarm's data is inserted into my database and in that database I have a column which holds ids of my alarms. In that column goes count of all set alarm. For example, if I have alarm for every Monday and Thursday(2 alarms to be set) then in that column would be integer like: current last id + 2(because of 2 alarms). Every time -current last id- fetch from database.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download