[Java for Android App Development] danger_beast:
Hey devs I am working on a project for which I need to set multiple alarms on different days I am really confused on how to set the values of those alarms in sqlite and then retrieve them and make the alarm fire . Please help me on this ...... i cant think it logically also :crying:

my mainActivity contains a simple switch button when the user turns it on it fires the alarm

here is my code....

// Setting values to database!

int month = 0;

int day = 0;

int hour = 0;

int minute = 0;

I need idea on this part how to save the time for the alarms :(

// Setting values to database!

int month = 0;
int day = 0;
int hour = 0;
int minute = 0;

DatabaseHandler alarms = new DatabaseHandler(MainActivity.this);
alarms.open();
alarms.createAlarm(month, day, hour, minute);
alarms.close();

// Getting values from database!

DatabaseHandler alarmsGet = new DatabaseHandler(this);
alarmsGet.open();

String monthData = alarmsGet.getData();

alarmsGet.close();

// setting Time!

final Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 5);
cal.set(Calendar.YEAR, 2014);
cal.set(Calendar.DAY_OF_MONTH, 28);
cal.set(Calendar.HOUR_OF_DAY, 15);
cal.set(Calendar.MINUTE, 55);
cal.set(Calendar.SECOND, 0);

context = MainActivity.this;
Intent intentAlarm = new Intent(context, AlarmReciver.class);

pendingIntent = PendingIntent.getBroadcast(context, 111, intentAlarm,
PendingIntent.FLAG_UPDATE_CURRENT);

alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), pendingIntent);

DatabaseHandler

import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHandler {

private static final String DATABASE_NAME = "alarmDatabase";
private static final String DATABASE_TABLE = "alarms";
private static final int DATABASE_VERSION = 1;

public static final String KEY_ROWID = "_id";
public static final String KEY_MONTH = "_month";
public static final String KEY_DAY = "_day";
public static final String KEY_HOUR = "_hour";
public static final String KEY_MINUTE = "_minute";

private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;

private static class DbHelper extends SQLiteOpenHelper {

public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
+ " INTEGER PRIMARY KEY AUTO INCREMENT, " + KEY_MONTH
+ " INTEGER, " + KEY_DAY + " INTEGER, " + KEY_HOUR
+ " INTEGER, " + KEY_MINUTE + " INTEGER);"

);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}

}

public DatabaseHandler(Context c) {
ourContext = c;
}

public DatabaseHandler open() throws SQLException {
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}

public void close() {
ourHelper.close();
}

public long createAlarm(int month, int day, int hour, int minute) {
// TODO Auto-generated method stub
ContentValues values = new ContentValues();
values.put(KEY_MONTH, month);
values.put(KEY_DAY, day);
values.put(KEY_HOUR, hour);
values.put(KEY_MINUTE, minute);
return ourDatabase.insert(DATABASE_TABLE, null, values);
}

public String getData() {

String[] columns = new String[] { KEY_ROWID, KEY_MONTH, KEY_DAY,
KEY_HOUR, KEY_MINUTE };

return null;
}
}