Java – Android, storing and retrieving text

Android, storing and retrieving text… here is a solution to the problem.

Android, storing and retrieving text

I’m currently working on an Android app for my university, let me give you a quick introduction:

There is a story that the player can read, then he has 3 choices, he will choose one, another story will appear again, there are 3 choices, and so on … (But each choice leads to a completely different story).

As you might expect, I have a lot of text to store, categorize, and retrieve. The first page shows the first story and 3 choices, if the player selects and clicks a button, the following story will appear, but it can also mean the end (obviously, if I keep 3 paths X 3 paths X 3 paths … It will get complicated)



So my first guess was to use an xml file, one containing each story and the other containing each selection.

At the beginning of the application, I would use the parser to traverse the file and put each string into a tree structure. (So I think one tree represents the story and the other represents choice).

I want to construct it with numbers, for example, if you are now at 1 and you click on select 2, then you

add another 2 at the end of the previous story and it becomes 12, then if you click on select 3, it becomes 123 and so on…
I’m easier for trees though, alas, xml only gives a tag name, so I’d like to use story1, story11, story12, story13, etc….

What the structure of my xml should look like (or my tree)

But since I want to use numbers, it’s already cumbersome to classify it in the tree, I have to get a string using parser.parName(), and then I need the substring to get the number at the end, and just to retrieve which node it should go to to get some resources.

In other words, the more I

think about it, the more complex my thoughts become, so I need some smart people to tell me where to go. (Obviously already lost on the road)



If you think you’re smart, that’s my problem

What would you use to store text? An XML file? Will you use a tree afterward? How would you do this to efficiently sort the XML into the tree?

It seems that my explanation is a bit messy, if there is something you don’t understand, please let me know. (or if it’s my broken English).

Thanks for the answer!


Personally, if I didn’t need to translate any of your Assets, I would put each scene in a JSON file, and each selection has a key pointing to the next filename. You can load the first file (or the last saved file) at runtime. The file name of the scene will be “Save” itself.

However, if you need to translate any storyline, you may want to dump it into “strings.xml” and then create a tree at runtime and reference the corresponding R.string id. However, in this case, R.string id should not be used as a save, as it can be changed between compilations. Each story scene should have a scene ID that should never be modified (an enumeration will do


Related Problems and Solutions