[feedhenry-dev] New fh-sync-android initialization - Episode: Sync Service
Vojtech Sazel
vsazel at redhat.com
Mon Sep 25 13:02:59 UTC 2017
Hi,
thanks for your recommendations on the pull request https://github.com/
feedhenry/fh-sync-android/pull/3
<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:
@Overrideprotected 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():
@Overrideprotected 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
<https://www.redhat.com/>
Remote Czech Republic
vsazel at redhat.com IM: vsazel
<https://red.ht/sig>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/feedhenry-dev/attachments/20170925/cbe598d8/attachment.htm>
More information about the feedhenry-dev
mailing list