开发者

How to store state in an Android Service

开发者 https://www.devze.com 2023-04-13 04:46 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号