I have a service which is started by a BroadcastReceiver that activates when the boot is completed. So the service starts and I have the following on my onStartCommand
public int onStartCommand(Intent intent, int flags, int startId) {
mQueue = Volley.newRequestQueue(getApplicationContext());
//FROM NOW ON I WANT IT TO LOOP CONSTANTLY
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, API.getDeviceTypes(), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
processResponse(response);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("mytag", "Error de response");
error.printStackTrace();
}
});
mQueue.add(request);
// LOOP TILL HERE
return START_STICKY;
}
I want the service to make that request constantly or at least every 3 minutes or something. How can I achieve this? As of now the service starts ok but of course it only executes those lines once.