我应该使用SQLiteSQLite

2023-09-07 03:06:13 作者:无限谅解

首先,我说这个我没有做过并使用SQLite应用我正在开发一个类似的调查project.I要保存回答用户的提问一个字符串数组和一个整数数组的答案(有5个选择,它们保存到数组作为0,1,2,3,4),当用户关闭该项目。我应该使用SQLite?有没有一个更合乎逻辑的方式?

First I say this I have not done before and the application with Sqlite I'm developing a similar survey project.I want save a string array for user's questions answered and an integer array for answer(there are 5 choice and they are saving to array as 0,1,2,3,4) when user closes the project. Should I use Sqlite?is there a more logical way?

推荐答案

我会说不,如果你保存的东西是pretty简单。结果我将使用SQLite的情况下,你需要一些relationalship或复杂查询。你的情况,你可能只存储在共享preferences一切(如果你能告诉我们一个例子,我们可以引导你)。

I would say "no", if the stuff that you're saving is pretty simple. I would use sqlite in case you need some relationalship or "complex" query. In your case you can probably just store everything in the SharedPreferences (if you can tell us an example we can guide you).

您也可以考虑写入文件的对象(地图,或列表,或其他),或将其保存为JSON。

You can also consider to write to a file your object (a map, or a list, or whatever), or saving it as json.

File file = new File(context.getDir("data", Context.MODE_PRIVATE), PRESETS);
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
outputStream.writeObject(myObject);
outputStream.flush();
outputStream.close();
 
精彩推荐
图片推荐