New fh-sync-android initialization - Episode: Sync Service

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

New fh-sync-android initialization - Episode: Sync Service

Vojtech Sazel
Hi, 

thanks for your recommendations on the pull request https://github.com/feedhenry/fh-sync-android/pull/3 
I created Android Service to handle the Sync.
Old static code in Sync.java was removed and my attempts with SyncableActivity as well.

1) So now initialization in activity goes like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
      //:
      //:
      //binding of the service
      serviceConnection = FHSyncService.bindService(this, syncService - > {
          Log.d(TAG, "activity connected to service ");
          syncService.setConfig((new FHSyncConfig.Builder()).useCustomSync(false).syncFrequencySeconds(10).notifyEnableAll().build());
          syncService.setCloudUrl("http://192.168.233.1:3000/sync");
          syncService.manage(DATA_ID, null, new JSONObject());          
      });
}

2) For safe calling on service after initialization, you can then use call() method somewhere:
serviceConnection.call(syncService -> {
            FHSyncListener.Builder builder = new FHSyncListener.Builder();
            builder.onSyncCompleted(msg -> {
                //...........
            });
            syncListener = builder.build();
            syncService.registerListener(syncListener);
        });
3) And unbind onDestroy():
@Override
protected void onDestroy() {
    //<<--- sync listener unregistration would go here
    unbindService(serviceConnection); 
    super.onDestroy();
}

4) Sync service needs to be added to AndroidManifest.xml
<service
      android:name="com.feedhenry.sdk.android.FHSyncService"
      android:exported="false">
</service>
Changes are still in PR here, please review: https://github.com/feedhenry/fh-sync-android/pull/3
Modified sync-android-app Activity with new initialization:
https://github.com/wojta/sync-android-app/blob/6d47e97cd6518ea910f030ae44555fa6dbc74f74/app/src/main/java/com/feedhenry/sync/activities/ListOfItemsActivity.java

github: https://github.com/wojta/sync-android-app/tree/sdk-improvements

--

VOJTĚCH SÁZEL

SENIOR QUALITY ENGINEER, MOBILE QE

Red Hat 

Remote Czech Republic

[hidden email]    IM: vsazel


_______________________________________________
feedhenry-dev mailing list
[hidden email]
https://www.redhat.com/mailman/listinfo/feedhenry-dev