2
I’m making an application, where has a job registration in Sqlite that should be synchronized with the server in PHP with Mysql.
After doing a lot of research, I couldn’t find any answers to my question.
I’m basing my synchronization on mode Incremental as this response suggests. /a/146592/97220
So for example, when the user finishes the registration, the application inserts the data into the Sqlite, and creates a version of data, and at the same time already tries to communicate with the server to send the entered data. When it arrives on the server the PHP query if the version is newer, and changes the data and sends the completion response pro application.
As I demonstrate in this animation:
So far everything is great and working.
Now my problem is in offline mode and when the connection falls in the middle of synchronization.
For example. I register a new item, create a data version on mobile even when offline. When I connect, I need to know how the app detects that data is still not sent.
And when the data is sent, but the connection falls in the middle of the way. As my application may know that there is still data that need to answer?
The problem would be more or less like in this animation:
And, after the crash, the application will not be able to try to enter the data again, because the version on the server will already be updated, and will not return update response.
Did I understand? I don’t know if I could explain it properly.
My problem is being with logic to solve when this kind of error happens.
I am very grateful if someone can give me a light without negativing me. I don’t know any other way to ask this question.
Thanks for the great explanation. I didn’t know this function of time.schedule. But one last question. In this case if for example there is an error on the phone and application close, the timer will be canceled right, as you explained. So I’m thinking of using your tips, but with service. But I’m afraid of being a problem to occupy too much the memory of users with older and weak device, since the service continues running even with the application closed. My question is... Do you have any special tips to use service without taking up too much memory, or is this just my paranoia, and I can do it quietly?
– Samanta Silva
@Samantasilva I think more paranoid, the
Service
will just do his job and after that you kill him, will not leave him running endlessly, to do this check when the app NAY is open from time to time you can use aAlarmManager
, that from time to time is activated if the app NAY is open, you can configure it to work this way, because if with the app open you already use thetimer
, doesn’t need theService
also, that would spendmemoria
for nothing– Woton Sampaio
Got it, thank you so much for the answers. Helped me a lot. I’ll put in practice. Bjss
– Samanta Silva