//create a callback interface
interface Callback { void onData(Map<String, String> mappedData); }
Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() {
refreshVars(firstname, lastname, id, new Callback() {
void onData(Map<String, String> mappedData) {
}
};);
String newlastdate = varList.get("newlastdate");
String newcurrentdate = varList.get("newcurrentdate");
}
handler.postDelayed(this, 60000);
}
};
handler.postDelayed(runnable, 60000);
public void refreshExitVars(final String FN, final String LN, final String IDN, final Callback callback){ final Map<String, String> list = new HashMap<>(); Response.Listener<String> responseListener = new Response.Listener<String>() { @Override public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
String nlastdate = jsonResponse.getString("date");
String ncurrentdate = jsonResponse.getString("currentdate");
list.put("newlastdate", nlastdate);
list.put("newcurrentdate", ncurrentdate);
callback.onData(list);
} else {
int ErrorCode = jsonResponse.getInt("errorcode");
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(Exit.this);
builder.setMessage("" + ErrorCode)
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
this.finish();
}
})
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RequestUIChanges requestUIChanges = new RequestUIChanges(FN, LN, IDN, responseListener);
RequestQueue queue = Volley.newRequestQueue(Exit.this);
queue.add(requestUIChanges);
}
// Check out the bold text. Correct any syntax errors. I've just typed it here.