I'm trying to run a function inside a thread, and use the data afterwards. The obvious problem is that the main thread isn't waiting (If that's what happens) Though a pretty simple question, searching the internet didn't provide me any solution unfortunately. Any advice how to implement it properly?
Thread:
MainActivity.this.runOnUiThread(new Runnable() { // A new thread to get the currencies
@Override
public void run() {
jsonConversion(mMessage);
}
Function:
public void jsonConversion(String mMessage) {
try {
JSONObject srcJson = new JSONObject(mMessage); // 2 objects, rates and base
rates = srcJson.getJSONObject("rates"); // Currencies map
baseCurrency = srcJson.getString("base"); // Base currency
lastUpdate = srcJson.getString("date"); // Last update
} catch (JSONException e) {
e.printStackTrace();
}
}