我有一個非常基本的應用程序,它使用Maps API來顯示地圖,長按之後它會在該位置放置一個標記。如果您選擇其他位置,它將刪除當前標記並創建一個新標記。在android中存儲少量數據的最佳方式
該應用程序做了我目前所需的操作,但是我可以在應用程序關閉後繼續使用數據。
這就是我正在嘗試做的:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
BufferedReader reader;
try {
final InputStream file = getAssets().open("userLatLng");
reader = new BufferedReader(new InputStreamReader(file));
String line = reader.readLine();
line = reader.readLine();
System.out.print("Getting Data");
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
即用於應用程序啓動後
String filename = "userLatLng";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(Integer.parseInt(yayaParking.toString()));
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
,應該是如何保存數據讀取數據。我還沒有得到這個工作,所以任何幫助,將不勝感激!
將它保存在共享偏好設置中https://developer.android.com/training/basics/data-storage/shared-preferences.html –