E
E
eremeevdev2013-12-27 15:55:03
Android
eremeevdev, 2013-12-27 15:55:03

Android REST client implementation and synchronization with gcm

Good afternoon. There is a task to develop an android client for a news site. Gcm is supposed to be used to notify about new entries.
Estimated algorithm:
1. Launching the application, the database is empty, we make a request to api, we get the last 20 records, id from 1000 to 980, we write it to the database.
3. Scroll the listview to the last entry, make a request for entries whose id is less than 980, get entries from 979 to 959 and write to the database.
3. A gcm message arrives, or the update button is pressed, we make a request to api, we get records with id > 1000, we get records with id 1001 to 1021 and write them to the database.
The question arises - how to behave correctly in a situation where, suppose the device has been offline for a week, during this time another 1000 records have been added.
The device connects to the network, receives a send-to-sync message, makes a request to the api to get records with id > 1021, 1000 records should come in response.
Intuition tells you that it is not correct to download all 1000 records, but you need to download, say, the last 20, but then it turns out that there will be news for today in the database, there will be no news for the last week, and then there will be news for the week before last
And question number 2 - how to properly clear old records to prevent the database from growing indefinitely?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eremeevdev, 2014-01-08
@eremeevdev

How will it not be if you have an algorithm for obtaining previous records. When the user scrolls through 20 entries, he will receive the previous 20.

Let me explain the algorithm of work a little:
before making a request to receive records from the server, we find out the id of the last record in the database, and only then we make a request to receive records from the server whose id is greater than the id of the last record in the database. Here, however, the problem of the infinite growth of the base arises.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question