I have a service that connects to the server at a certain interval and checks the last id in the database. If the server id is more than my preferences , then a notification comes. The problem is that if the user updates the list and receives new entries, the service will still send a notification. I decided to take the last JSONObject id when loading data and save it in the preferences .
//если произошла ошибка при загрузке //или от сервера пришел null //то сохранение в БД не будет происходить //список будет формироваться только из сохраненных if (json != null || !json.equals("null")) { JSONArray messages = new JSONArray(json); for (int i = 0; i < messages.length(); i++) { //берем каждый JSONObject JSONObject message = messages.getJSONObject(i); //берем id String id = message.getString("id"); //сохраняем последний id //чтобы сервис не показывал ложную инфу if (i == message.length() - 1) { editor.putInt("lastid", Integer.parseInt(id)); editor.commit(); }