Search code examples
javaandroidsharedpreferencesandroid-alarms

SharedPreferences not updating in onResume()


I am new to Android programming, I am trying to develop an app which is used to set alarms. As the AlarmManager will lose all the alarms on system reboot, so I saved all the alarms being created by the user using SharedPreferences.

I have a main activity, which lists all the alarms. I have an alarm_create activity which creates the alarms. alarm_receiver class is called as PendingIntent when the alarm goes on.

Now even if the alarm_receiver makes changes in the alarm, it is not reflected in the main_activity when the application resumes.

For saving the alarm, I have used the concept of queue which would help me retrieving the alarms in loop.

Please help me with the problem.


Solution

  • Actually, SharedPreferences do not get updated instantly, it gets updated when the Application is restarted.

    Unfortunately, restarting an application is not that easy to code in Android, and is out of scope for your Application.

    The above answer by DecodeGnome, can be used to relaod the list or reload the application's alarm.

    I'll suggest you to go for SQLiteDatabase Class, and store the alarms in SQLite Database, as every Android device has SQLiteDatabase.

    You can see the reference code here.