My main activity uses the handy WakefulIntentService by CommonsWare to schedule an alarm that polls my server for changes in data. When the alarm fires, I call a service:
Intent backgroundIntent = new Intent(context, PollService.class);
WakefulIntentService.sendWakefulWork(context, backgroundIntent);
The service reads a piece of server data, 'token' and compares it with an 'oldToken' value stored in preferences. If the tokens do not match, I send a notification with a pending intent to start an activity.
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String oldToken = settings.getString("oldToken", "empty");
Log.d(TAG, "Old token: " + oldToken);
if (!token.equals(oldToken)){
...
This works fine for a while, but after a random number of hours, 'oldToken' starts returning 'empty' as if the service can no longer access shared preferences.
Then I noticed this shows up in logcat:
03-12 08:32:51.325 506-7595/? W/BroadcastQueue﹕ Unable to launch app com.xxx.xxx/10086 for broadcast Intent { flg=0x14 cmp=com.xxx.xxx/com.commonsware.cwac.wakeful.AlarmReceiver (has extras) }: process is bad
I've been trying to think if these two events are related. They do seem to occur at the same time.
Why am I getting the "process is bad" error? Why does my service lose my connection to shared preferences?
Thanks for your consideration.