ferrannp / react-native-sync-adapter Goto Github PK
View Code? Open in Web Editor NEWSchedule background data synchronization using React Native.
License: MIT License
Schedule background data synchronization using React Native.
License: MIT License
When I change syncInterval value and recompile the effective sync period is still 1 min.
I reproduce with the provided example project.
So it becomes more familiar for Android users.
This
react-native
repo.Facing the error Expected to run on UI thread
. When the task is running.
"react-native-sync-adapter": "^2.0.0",
Dependencies:
"react": "16.0.0-alpha.12",
"react-native": "0.48.1",
Sometimes I am getting the error as Object is not a function (evaluating 'taskProvider()(data)')
Im trying to integrate this in my RN project, every-time app goes background, the app crashes.
Logcat error output
Process: app.my.com, PID: 16407
java.lang.RuntimeException: Unable to start service com.fnp.reactnativesyncadapter.HeadlessService@89518c2 with Intent { cmp=app.my.com/com.fnp.reactnativesyncadapter.HeadlessService }: java.lang.ClassCastException: host.exp.exponent.MainApplication cannot be cast to com.facebook.react.ReactApplication
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3027)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassCastException: host.exp.exponent.MainApplication cannot be cast to com.facebook.react.ReactApplication
at com.facebook.react.HeadlessJsTaskService.getReactNativeHost(HeadlessJsTaskService.java:171)
at com.facebook.react.HeadlessJsTaskService.startTask(HeadlessJsTaskService.java:100)
at com.facebook.react.HeadlessJsTaskService.onStartCommand(HeadlessJsTaskService.java:52)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
In react-native 0.60.2
HeadlessJsTaskConfig does not take null data. SO answer
Code need to be modifed as follow:
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
.
.
WritableMap data = Arguments.createMap();
I can submit a PR if allow.
Add optional flag to allow task to run when the app is in the foreground.
React native : 0.64.1
When i tried to run the release apk build I am getting below error :
node_modules\react-native-sync-adapter\android\src\main\res\xml\authenticator.xml:2: AAPT: error: resource mipmap/ic_launcher (aka com.fnp.reactnativesyncadapter:mipmap/ic_launcher) not found
But this is not coming in case of debug apk.
Implement and export syncImmediately
. Task can be fired for example by a broadcast receiver.
Send notifications when task is fired instead of making use of console.log
.
The given example is not logging anything ( or outputting"Headless JS task was fired!") at the chrome debug or "adb logcat" console, though the app is not running in the foreground (app closed). Could you please check this or if there is anything which I missed, let me know. Thanks.
Device : Moto E 1st Gen
OS: Android 5.1
PS: Wanted to use rn-sync-adapter to check location of the device every 3 mins in a production app
I have successfully implemented the react-native-sync-adapter
and is working fine for the foreground and background sync. But the main issue is, I want to stop the sync interval task after single sync. I want to sync the data only once when user taps on the sync
button in the application. Can anyone help me how to achieve that?
I am registering the task like:
const TASK_ID = 'TASK_SYNC_ADAPTER';
AppRegistry.registerComponent(appName, () => SyncAdapterExample);
AppRegistry.registerCancellableHeadlessTask(
TASK_ID,
() => TestTask,
() => {},
);
And canceling the task after my operation has been completed in TestTask.js
file like:
const TASK_ID = 'TASK_SYNC_ADAPTER';
AppRegistry.cancelHeadlessTask(TASK_ID, TASK_ID);
But I am getting an error while canceling the task:
TypeError: taskCancelProvider() is not a function. (In 'taskCancelProvider()()', 'taskCancelProvider()' is undefined)
Default right now is 5 minutes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.