In the service, I have a timer at the end of which a request to the server goes:
public void timerToConnect() { final CountDownTimer countDownTimer = new CountDownTimer(1000 * 60 * TIME_TO_REQUEST, 1000 * 60 * TIME_TO_REQUEST_INTERVAL) { @Override public void onTick(long l) { } @Override public void onFinish() { getDataFromServer(); } }; countDownTimer.start(); } Here is the method itself:
public void getDataFromServer() { StringRequest stringRequest = new StringRequest(Request.Method.POST, API_URL, new Response.Listener<String>() { @Override public void onResponse(String response) { if (!response.isEmpty() && JSON_Utils.isJSONValid(response) && !response.trim().equals("\"error\"")) { ReadData readData = new ReadData(response); List<MainModel> mainList = readData.getMainModelList(); } timerToConnect(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("CONNECTION", "Ошибка при подключении к сети " + error); getDataFromServer(); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<>(); params.put("tvid", GlobalData.getTvId(getApplicationContext())); return params; } }; stringRequest.setRetryPolicy(new DefaultRetryPolicy( 20000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); Volley.newRequestQueue(this).add(stringRequest); } In the debug shows Timer that eats a lot. I also think that Volley needs to be cleaned. Although I do not know how. Tell me how to make the timer not consume a lot of memory in the service, as it makes a request every 5 minutes
ReadDataclassReadData? - iksuytimerToConnectis being calledtimerToConnect, in whichgetDataFromServerisgetDataFromServerin which `timerToConnect is called in, in which inside ...? - iksuygetDataFromServerisgetDataFromServer> after parsing the data back>timerToConnectto get the timer back up and after the timergetDataFromServerbackgetDataFromServerand so on ... - DevOma