AlarmManagers in Android lose all of their registered alarms when phone loses power.
I use the following broadcast receiver to trigger at android bootup:
public class AlarmBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Cursor alarmCursor = MainActivity.dbHelper.loadAlarms();
// Iterate through every stored alarm and set those alarms.
// ....
alarmCursor.close();
}
}
}
When the broadcast receiver's onReceive is triggered at system bootup, what context parameter is given to the method? I have to know the context, because I need the context to cancel alarms set in that context.
I am assuming the call to MainActivity.dbHelper.loadAlarms() is not safe because MainActivity is not initialized in system bootup. Or is it safe because dbhelper and loadAlarms() are all initialized and declared static?