Is there any AJAX asynchronous callback method in Android?

I was wondering if there is a way to create asynchronous callback functions in an android client like AJAX by binding an event handler to the event received with the response. I am looking for something like this:

  • The client sends data via POST or GET to the server, and the application is not blocked, waiting for a response.
  • The server processes the data and sends a response.
  • The application receives a response, and at this time an event is created and its event handler is executed.
+4
source share
2 answers

You can use droidQuery to use Ajax syntax. This library uses AsyncTask to run queries in the background. A simple example:

$.ajax(new AjaxOptions().url("http://www.example.com").type("GET").dataType("json").success(new Function() { @Override public void invoke($ d, Object... args) { JSONObject json = (JSONObject) args[0]; //TODO handle json. If expecting a JSONArray, just cast args[0] to JSONArray. } }).error(new Function() { @Override public void invoke($ d, Object... args) { AjaxError error = (AjaxError) args[0]; Toast.makeText(MyActivity.this, "Error (" + error.status + "): " + error.reason, Toast.LENGTH_LONG).show(); } })); 
0
source

Source: https://habr.com/ru/post/1343528/


All Articles