简体   繁体   中英

How/where can I “stash”/keep data in my application?

I display dates to the user in a layout that are let's say are textual.
When the user presses a button I want to get the information in those fields that represent these "dates" but if I get the text in them is not of value to me.
I would need to store somewhere the original dates that created these "textual" elements and fetch them from there.
Is there a specific construct in android that one can use as a stash area or should I just use a static class with variable to hold them?

In your case, you should use SharedPreferences to store the data by converting it into a String (text) or int/long first. This will allow you to easily write and retrieve data, and you should use this.

You can also use the file system to save almost any Java object using serializable , on Internal Storage.

Either way, the data will stay there even if your app is closed or the device is turned off.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM