This issue does not include Livedata. I have read through several questions but have not found the answer to my issue the file below gives the error. simulatedUpdate() is called from a background Thread. The problem is with the call receivedLocationUpdate() method that is being called within simulatedUpdate(). I assume the parameters passed are calling the set... methods in some way. I need to know why this occurs and how I can call this method in the current situation.
public class LogDataSimulation {
SharedPreferences defaultPreferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.getAppContext());
private static final String TAG = "LogDataSimulation";
public static boolean simulatedDataEnabled;
WMManager wmManager = new WMManager();
public LogDataSimulation() {
simulatedDataEnabled = defaultPreferences.getBoolean(kSimulationMode, false);
}
public synchronized void simulatedUpdate() {
InputStream logFileStream = null;
try {
AssetManager assetManager = MyApplication.getAppContext().getAssets();
logFileStream = assetManager.open("file.csv");
InputStreamReader streamReader = new InputStreamReader(logFileStream, Charset.defaultCharset());
CSVReader reader = new CSVReader(streamReader);
String[] nextLine;
double headingAccuracy = 0.0;
double strideAccuracy = 0.0;
double currentStepLength = 0.0;
int totalStepCount = 0;
double cumulativeDistance = 0.0;
double latitude = 0.0;
double longitude = 0.0;
double altitude = 0.0;
double userHeading = 0.0;
Location globalLocation = new Location("");
int floorID = 0;
double stepBias = 0.0;
double stepBiasAccuracy = 0.0;
double orientationBias = 0.0;
double orientationBiasAccuracy = 0.0;
TestUpdate update = new TestUpdate();
boolean header = true;
while ((nextLine = reader.readNext()) != null) {
if (nextLine[2].equalsIgnoreCase("data")) {
//Throw the header.
if (header) {
header = false;
continue;
}
headingAccuracy = Double.valueOf(nextLine[17]);
strideAccuracy = Double.valueOf(nextLine[22]);
currentStepLength = Double.valueOf(nextLine[24]);
totalStepCount = Integer.valueOf(nextLine[25]);
cumulativeDistance = Double.valueOf(nextLine[26]);
latitude = Double.valueOf(nextLine[30]);
longitude = Double.valueOf(nextLine[31]);
altitude = Double.valueOf(nextLine[32]);
userHeading = Double.valueOf(nextLine[36]);
globalLocation = update.globalParticlesLocation();
floorID = 10000;
stepBias = Double.valueOf(nextLine[39]);
stepBiasAccuracy = Double.valueOf(nextLine[41]);
orientationBias = Double.valueOf(nextLine[43]);
orientationBiasAccuracy = Double.valueOf(nextLine[46]);
Thread.sleep(1000);
}
wmManager.receivedUpdate(longitude, latitude,
altitude, totalStepCount, cumulativeDistance, currentStepLength,
strideAccuracy, userHeading, headingAccuracy, floorID,
globalLocation, stepBias, stepBiasAccuracy, orientationBias,
orientationBiasAccuracy);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
The Logged Error is: I get a W/System.err: at com.app.navigationSimulation.LogDataSimulation.simulatedUpdate(LogDataSimulation.java:95) Line 95 is the the call to wmManager.receivedUpdate() and the Exception message: Cannot invoke setValue on a background thread