Estoy consumiendo los datos de un Api Rest desde android usando la librería volley. El código no me está generando ningún error y está mostrando los datos correctamente, pero si uno de los datos cambia en el API es necesario realizar un Refresh para obtener el nuevo dato.
Solo quiero saber si es posible que el cambio se realice automáticamente al detectar un cambio en los datos contenidos en el servicio.
private fun showCompanyRequest(){
// Instantiate the RequestQueue.
val queue = Volley.newRequestQueue(this)
// Request a string response from the provided URL.
// Request a string response from the provided URL.
val stringRequest = StringRequest(Request.Method.GET, url,
Response.Listener<String> { response ->
// Display the first 500 characters of the response string.
val jsonArray = JSONArray(response)
for (i in 0 until jsonArray.length()) {
val response = jsonArray.getJSONObject(i)
textView.text = response.getString("Nombre_Empresa")
}
},
Response.ErrorListener { textView.text = "That didn't work!" })
// Add the request to the RequestQueue.
queue.add(stringRequest)
}
Actualmente este método se encuentra contenido dentro de un SwipeRefreshLayout y el objetivo sea que el cambio se detecte automáticamente y se realice la actualización de la información.