How to store state in an Android Service
I'd like to make my IntentService
remember when it was called last time and how many times it was called so far. It doesn't matter if these values are reset when the phone is rebooted, but they must not be reset when the application process is killed.
Should I store these state variables in a Shared开发者_运维技巧Preferences
, or is there is a better and/or more lightweight way? I tried intent.getExtras()
, but it seems that the values I put there are not remembered between calls.
For persistent storage like this, SharedPreferences
is usually the way to go. And don't forget to do commit()
after editing the preference.
精彩评论