w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Syncing with server

Android sync framework should be pretty good for your use. If you mark a sync as needed, the system will not launch it right now, but delay it for a small time. This way, if the user switch back the button, you'll be able to notice that no value has changed. Sidenote: if you use a ContentProvider, it notifies the SyncAdapter automagically when data changes. You can also trigger a sync manually if needed.

What the sync framework do is just calling a method (onPerformSync). You're free to implement it as you want. You can skip a sync if you think the last one was too close, or find if data has really changed, or it's back to original value (you can for example keep the "last synced" value in your database, then you can compare it to the current value in your onPerformSync method. If it's the same, no change).

Bonus: you'll save battery power, as the sync framework run multiple syncs in sequence as much as possible, your users will be able to manage their accounts in a centralized place (Android settings), disable sync system-wide (think about Sony's stamina-mode, setting every SyncAdapter in pause while active).





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.