简体   繁体   中英

Can I Use string.xml resources as a data base?

I'm using in my Flashcards app strings.xml (value folder) as a database from where I extract the Questions & answers. Some colleagues told me that I'm miss-using string.xml!? I really don't see any drawback using strings.xml as a database? Do you agree with me regarding this point? Do yo have better solution I mean better source code of a flashcards app to learn from it the best practices.

here is my code:

resId1=getApplicationContext().getResources().getIdentifier(
                "textname" + 1, "string", getPackageName());

        tex1=getResources().getString(resId1);

Many thank for your thoughts and assistance.

可以将strings.xml用作只读数据库,只要您不需要联接数据或对其进行更多高级搜索即可。

Using strings.xml is no different than using a text file as a "database" (I use that term lightly here).

You have to decide what's better for you here. Do you prefer to have a text file as a source of your data (which under certain circumstances can be completely viable) or do you need more control over your data (join, search, etc.).

If so, you can use the built in SqlLite to allow you to use an RDMBS but if not and you don't need to do anything other than having a read-only source of text, a text file approach is absolutely fine (even if it's in strings.xml).

I would suggest you to use Strings.xml as language file only, but if you think you don't have any confidential information's you are allowed to use Strings.xml as a database(but not recommended) however you can't store new values on runtime at Strings.xml.

To handle some fewer data you can use SharedPreferences to store them and retrieve them, by (key, value) simple to use. If u have large set of data then go for SQLite.

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