Try to read settings on BOOT_COMPLETED

I set the alarm from my application, and when I reboot, I see that 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 should be correct.

When I try this line of code below, I am having problems. I need to get the time needed to set the alarm, but it looks like I can’t access the prefixes of my application (the so-called S), because my application never started. NullPointerException:

if ( S.prefs.getBoolean(S.SCHEDULEDSTATUS, false) == true ) { }

I suppose it should be obvious that I cannot read the public static ending of an un-created action.

Should I keep my alarm time in a file or am I missing something?

+3
source share
1 answer

You need to access it through the context that you get in your receiver:

    public void onReceive(Context con, Intent intent) {

            final SharedPreferences settings = con.getSharedPreferences(PREFS, 0);

    boolean boolValue = settings.getBoolean(BOOL, false);
}
+4
source

Source: https://habr.com/ru/post/1782831/


All Articles