How to do sync with local database and parse?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:24:40

问题


I have an Android application where the app should work offline. In the app when the records are been created during offline mode they are stored in the local database(sqlite), when the internet connection is available the records that were been created during offline should sync with parse.

How can I do it in Android?


回答1:


Simple while run a background service to check whether your mobile is connected to internet or not,then get the data from your Local Database in one list and then Parse data into other list

public Collection nonOverLap(Collection coll1, Collection coll2) {
   Collection result = union(coll1, coll2);
   result.removeAll(intersect(coll1, coll2));
   return result;
} // will return elements missing in parse

Then update the nonOverlap into parse Db :)




回答2:


Look into firebase or couchdb or parse data objects

https://parse.com/docs/android/guide#objects

https://www.firebase.com/

http://www.couchbase.com/




回答3:


Check if device is connected to the Internet:

public static boolean isDeviceConnectedToTheInternet(Context ctx) {

    NetworkInfo networkInfo =
            ((ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE))
                    .getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

Then choose a scenario.



来源:https://stackoverflow.com/questions/32796625/how-to-do-sync-with-local-database-and-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!