I am setting an alarm from my app, and when rebooting, I see I need to reset the alarm since it does not survive reboots. I created a broadcast receiver to receive BOOT_COMPLETED and this works so my manifest must be correct.
When I try this line of code below I get in trouble. I need to retrieve the time that I need to set the alarm to but it looks like I cannot access the prefs of my app (called S) because my app has never started. NullPointerException :
if ( S.prefs.getBoolean(S.SCHEDULEDSTATUS, false) == true ) { }
I suppose it should be obvious that I cannot read a public static final of an activity that has not been created.
Do I have to store my alarm time in a file or am I missing something here?
You have to access it via the context you get in your reciever:
public void onReceive(Context con, Intent intent) {
final SharedPreferences settings = con.getSharedPreferences(PREFS, 0);
boolean boolValue = settings.getBoolean(BOOL, false);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With