I'm having trouble accessing my preferences from a BroadcastReceiver
. I'm using the following code:
public class MyReceiver extends BroadcastReceiver
{
private static final String TAG = MyReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent)
{
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(
context.getApplicationContext());
Log.d(TAG, sharedPreferences.getAll().toString());
}
}
This code always prints stale preferences. When I go to my PreferenceActivity, change settings and then fire an event that triggers the above BroadcastReceiver
it always prints old values for the preferences.
I also added the same code to my main activity and it always prints the correct settings.
What is going on here? Are the settings being cached? Is there a way to force a reload from my BroadcastReceiver
?