Search code examples
androidsharedpreferencestaskmanagercache-expiration

Android - does SharedPreference have a default expiration date?


Simply: all in title.

Details: My objective is to store data in SharedPreference until a developer manually clear them. Then I am wondering either:

1) SharedPreference DOES has a default expiration date and therefore my android device will automatically clear data stored in SharedPreference at some point

OR

2) SharedPreference does NOT have a default expiration date and therefore my android device will have data stored in SharedPreference forever unless a developer manually clears them.

+) Would it be possible that data in SharedPreference is cleared by android OS (background) task manager?

Which one is correct answer? Or, am I missing something?

Any input will be greatly appreciated.

Regards,


Solution

  • SharedPreference DOES has a default expiration date and therefore my android device will automatically clear data stored in SharedPreference at some point

    No.

    SharedPreference does NOT have a default expiration date

    Yes.

    and therefore my android device will have data stored in SharedPreference forever unless I do not manually clear them.

    No, assuming that the "I" in that sentence refers to you as a developer. The user can clear the app's data, which will get rid of your SharedPreferences as well.

    Would it be possible that data in SharedPreference is cleared by android OS (background) task manager?

    No. Android terminates processes to free up system RAM. It does not delete files, such as SharedPreferences, to free up system RAM.