简体   繁体   中英

How to manage data in android

I try to create a simple game and I wonder to what is the best solution to manage data in android. For example I have a simple game. A map of single a level is 2 dimensional array 3x3. On this map i have for example 3 kinds of objects: yellow circle, red circle, green circle. And I have more than 1000 levels. So what is the best solution to keep this level data?

1) I can create arrays for all levels in code:

String[][] level1 = new String[][]{{"y","b","g",}...}
...
String[][] level1000 = new String[][]{{"y","b","g",}...}

2) Or i can put it to some resource .xml file but how to keep it? In this resource file i can't create 2D array :/

Other question for this it is better to load all data at the beginning and put it to the some cache or load only when i needed data to the specific level?

What do you think?

You can use json formatted text file. You can save it in raw folder and whenever you need you can call it. Json parsing is too easy and you can find easily specific level. See this link for information.

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