He began to write the first thing that came to mind - a book with recipes. The bottom line is that the main screen is a ListView with headers and an "add" button. When you click on "add", another activity opens, in which the name of the recipe and its description are entered. From this data, a new object is created:

 public class Recipe implements Parcelable{ private String recipeName; private String recipeDescriptions; public Recipe(String recipeName, String recipeDescriptions) { this.recipeName = recipeName; this.recipeDescriptions = recipeDescriptions; } } //дальше реализация Parcelable 

When you click on Item in ListView , this recipe should be edited. At the moment, a new Activity implemented, in which recipeName and recipeDescriptions are transferred and entered into the corresponding EditText 's. Everything is edited and saved perfectly. However, when there was a question about saving objects, to restore them when the application was loaded, I just got stuck. Is it really impossible to do without a database? I think I suffered the wrong steppe.

Tell me, please, how best to implement storage and recovery at boot? Maybe I need to completely revise the concept of the application and do everything in any other way? Maybe you do not need to do the Recipe class at all, but do everything with String ?

  • 2
    It is best to put in the database. You can take NoSql solutions from Realm - it is fashionable and cool. You can store objects directly, no messing around with SQL`. - Yuriy SPb
  • If all you have is just a single collection of objects, then you can simply serialize them into JSON and save the file to a private repository. In general, I agree with the previous comment: Realm is extremely easy to connect and use. - Agrgg
  • But it will not happen that when you open an application with 200 recipes, 200 objects will start being created and everything will hang? - R1zen
  • If I'm not mistaken, RecyclerView able to work with complex and massive lists better than ListView , use it better, it is also more convenient. It definitely won't hang with him - Flippy
  • Your Recipe model can be replaced by Pair<String, String> , but it's worse ... It's better to take the name through getRecipeName - Flippy

1 answer 1

There are 4 options:

  1. To save data in SharedPreferences is a way for the poor, when you need to save a little bit and a bit
  2. The most correct way to save to the database, the standard in SQLite is a more modern way through Realm
  3. You can use various cloud options - the most native Android FireBase cloud service
  4. There is a fourth option, I don’t recommend using the standard Java mechanism implemented via the Serializable interface read / write via ObjectInputStream/ObjectOutputStream — with writing to an external file in Context.getFilesDir() .