I'm developing an app that listens to the gps positions on the wear side and write them on a file. As I want to keep this files synced on the handheld side, currently I'm adding the positions to a datamap as they are acquired:
private void addLocationEntry(double latitude, double longitude, float accuracy, long gpsTime, float speed, double altitude, long time){
String PATH = "/GPSdata";
if(!googleClient.isConnected()){
return;
}
String dataString = gpsTime + "\t" + time + "\t" + latitude + "\t" + longitude + "\t" + speed +
"\t" + distance + "\t" + accuracy + "\t" + altitude + "\n";
String name = new SimpleDateFormat("HH'h'mm'm'ss's'_dd-MM-yyyy").format(initialTime);
//make datamap and send it (GPSdata file)
DataMap dataMap = new DataMap();
dataMap.putLong(KEY_INITIALTIME, initialTime);
dataMap.putString(GPSinfo, dataString);
new SendToDataLayerThread(GPSdata + "/" + time, dataMap).start();
}
class SendToDataLayerThread extends Thread {
String path;
DataMap dataMap;
// Constructor for sending data objects to the data layer
SendToDataLayerThread(String p, DataMap data) {
path = p;
dataMap = data;
}
public void run() {
// Construct a DataRequest and send over the data layer
PutDataMapRequest putDMR = PutDataMapRequest.create(path);
putDMR.getDataMap().putAll(dataMap);
PutDataRequest request = putDMR.asPutDataRequest();
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleClient, request).await();
if (!result.getStatus().isSuccess()){
run();
}
}
}
The thing is that the user, at the end of the activity, can say that the data gathered until then is not to be stored in the files... So I want to delete all the datamaps sent in order to, on the handheld side, don't receive them..
In this moment I'm sending a datamap at a time every time it is created, that means that in the end, if the user dont want to store the data, all the datamaps have been already sent...
Is there a way to cancel the datamaps created or send them all at the end of the app (without over killing the memory)?