我的项目中有一些数据,如HR值,卡路里和皮肤温度,同样也会显示在图表视图的顶部。但是如何保存上述三个参数的值,以便用户可以随时通过单击历史记录按钮查看其先前的详细信息。应自动获取三个参数的数据。请帮忙 。
答案 0 :(得分:0)
如果您想将数据写入手机的外部或内部存储空间,以便可以读取这些数据,例如在应用程序结束后,在按钮的OnClick方法中,您可以使用http://developer.android.com/training/basics/data-storage/files.html。
所以1.你设置了从外部/内部存储写入/读取的权限:
<manifest ...>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
...
</manifest>
2。 使用outputStream保存任何原始数据类型,如String:
String filename = "myfile";
String string = "This text becomes written on internal storage";
FileOutputStream outputStream;
try{
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
3.Analog通过调用openFileInput()读取字符串并向其传递要读取的文件的名称。这将返回FileInputStream。使用read()从文件中读取字节。然后用close()关闭流。
您还可以编写和读取整个ArrayList。因此,您应首先在活动开始时从OnResume()中的内部存储读取最后一个ArrayLists,并始终在您的活动暂停时使用OnPause()将ArrayLists写入内部存储。 您可以轻松地添加或删除应该从ArrayList保存/删除的数据。