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.
Related
I want to create a javafx project, but does it need Database?
when I create this program save these name when I input this name and other. I mean save the result in the program and show me when I run it, I don’t need to be store for along time .just for that time when I will run it?
Short answer is no, JavaFX can run without database and you don't need to use it.
If you need to sava data that only while program is running but don't need to save it for next use of program then you can simply use some Collection or custom data structure to hold what you need in runtime, but bare in mind that this means that all data will reset once you quit program.
If you need to save data even when program shuts down then you will need to use some kind of database, if you want to save a small amount of data then you can use json, xml or even raw txt files, for more data you should take look at some SQL/NoSQL database.
I am creating an application that allows the user to store information about food recipes that they can share on social media. I have an activity that allows the user to upload an image, write ingredients and directions for the recipe. In the past I have worked with shared preferences for saving user information, however, I know that the information stored is unordered. So I want to know what type of storage I should use to achieve this outcome....
My activity that saves user data:
From this I want to load the information into a previous activities list view that will have this type of list element layout:
From this what type of storage approach should I take? if I use shared preferences can I just place the parts I need into the elements of the list manually, for example, extracting the image saved from the user and placing that inside the image section of the listviews? or will the limitations of shared get in the way and maybe use internal storage? what would be the best approach?
Form a structured JSON object out of your data and you can use REALM. It is a new and easy alternative to SQLite.
It is very fast, easy to learn and integrate in your app.
Also, it is scalable means if you decide that you will be taking the same data to your backend then it will be easy for you to handle large amount of data.
In my software I want to store some data, that later they will be used. Something like a database to hold data:
Date, source path, destination path, and an array of file names.
Also another table to hold information about ftp connection:
Host, port, username and password
I need to know what methods are available to store and parse these data. I noticed there is a file type called .csv, is this an option for me? And is there any other option?
I think this depends a lot on how much data you want to store and how you need to access it.
If your application is going to be collecting a lot of structured data, such as user profiles, or product information, ie, if your application is all about a database then, yes as others have commented some sort of SQL database would make sense.
If your needs are more along the lines of just storing some "session" information, maybe like the last state of a GUI form for example, you might want to just serialize the data and write it to a simple text file.
One simple way to do that would be to serialize the data in a human readable format such as JSON and then write the text to a file, and then read it back and deserialize it when you need to restore it from storage.
If this is what you are looking for take a look at gson (from google), it provides a very easy what to convert a java object to JSON and back again.
JSON, is just text, so you can just read and write it to a simple text file.
Plain and, hopefully simply...
-What I would like to do is make a list of strings.
-I would like to add to this list while in the application.
-Finally, I want to get each String from this list.
This must be saved somehow so that when you close it and open it back up, the list will save...
How should I get around to this? SharedPreferences? An SQL Database? What should I use to accomplish this?
I vote SharedPreferences since it will be faster and will persist throughout the life span of the application.
If you need to have the saved data made available during the next time the app is run, you will most likely want to use a DB
I have a dialog box that the user inserts various data through gui controls,
and this information is saved as an xml file (implemented in java).
The information stored in the xml file is configuration information
for the application.
I can manually modify the xml configuration file, but I also want to provide this capability through a UI as well.
So when the dialog is opened (for creation of configuration) a corresponding well-defined object is populated by the various values input by the user.
Once the user presses 'save' the information in the object is stored as xml.
Now I was thinking to provide the option for edit the file via UI. So the same dialog is displayed to the user, but this time with the configuration information already filled-in by the loaded file. The corresponding object is populated as well.
I am not sure what is the best way to modify the file at this point.
Should I use 2 objects, 1 that stores all the file's info and 1 that stores the modified values from the dialog, and start comparing the objects for changes so that I modify the file? Or should I delete the file and create a new one?
Which is the best approach, and how would I proceed in each?
Thank you
Consider the data flow. The user will work with the GUI and make changes. The moment they make a modification, the data on the GUI is out of step with the XML. If the user opts to save the data then a simple marshalling operation (trivial if using JAXB) will ensure that the XML is updated. You don't need to compare every field, there's no point - of course you have validated the contents prior to committing them to file. If the user opts to cancel then no marshalling takes place.
There is no need to make a backup and no need to compare what is already in the XML.
However, if the user needs to be able to undo a save (such as revert to previous configuration) then you'll need a backup structure (or maintain a stack of GUI models in memory). I would not recommend that approach, though, as you're just chucking in needless complexity. Users are typically happy with a Save or Cancel button and no Revert.
Keep it simple. Just overwrite the entire file using the updated object. Then you won't need any special code for each case. All you will need is one method to marshall the object into the file and one method to un-marshall it.