您需要将所有数据存储在本地数据库中,然后检查互联网连接是否可用,如果互联网可用,通过 API 调用将数据发送到网络,然后如果您收到来自的响应,则从本地数据库中删除数据服务器。这种方式在从服务器获得响应后删除您本地数据库的每一行。
对于此实现,您可以拥有:
- create a database on mobile
- Register User on Server, After registering client should get a response from server and a timestamp.
- Save timestamp and register a Pending Intent for 12 / 24 hrs to Start a Background Service that would Sync the Data to Server.
- In case of no availability of Internet while Service wants to Sync data, we should have a Broadcast Receiver that check for internet connectivity, and as soon as Internet is available it would silently Start Service (Sync Service) in background and send data to Server.
- Server would again send a response with timestamp, on receiving timestamp we delete our local Database, and repeat step 3. This cycle will keep on repeating.
我认为这应该达到目的。如果如何实现这一点,请发表评论。