Open shinnachot opened 2 years ago
@shinnachot, I am not sure, but you may need to resolve your promise:
await new Promise(async (resolve) => {
// For loop with a delay
const { delay } = taskData;
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log('Send data');
await BackgroundService.updateNotification({ taskDesc: 'Tracking...' + i });
await sleep(delay);
}
resolve();
});
+1
In my case the action start is called after a successful login. The action runs forever in the background and gets restarted during login with adjusted service values.
The action always runs the amount of times the app was killed simultaneously.
Personally I think the error has something todo with react native Appregistry.runApplication
always creating a new RootTag
@Rapsssito i modified the pkg code locally and when i adjust the onStartCommand like this it works.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final Bundle extras = intent.getExtras();
if (extras == null) {
throw new IllegalArgumentException("Extras cannot be null");
}
final Options bgOptions = new Options(extras);
createNotificationChannel(bgOptions.getTaskTitle(), bgOptions.getTaskDesc()); // Necessary creating channel for API 26+
// Create the notification
final Notification notification = buildNotification(this, bgOptions);
startForeground(SERVICE_NOTIFICATION_ID, notification);
HeadlessJsTaskConfig taskConfig = this.getTaskConfig(intent);
if (taskConfig != null) {
this.stopForeground(false);
this.startTask(taskConfig);
}
return START_NOT_STICKY;
}
Dont know if this solves the problem, but worked for me
@fabiros, could you create a PR with your code so we can have this "fix" in a branch at least?
@Rapsssito done
This issue should be fixed by #124. Feel free to reopen if the problem persists.
I have reopened the issue since I had to revert the PR (#124) because it was creating another issue: #126.
Does any one found the solution for this?
I using this code when i want to start some task
BackgroundService.start(this.taskRandom, options);
When i kill app or logout i use this code to stop taskBackgroundService.stop();
It's work fine but...when i try to start task againBackgroundService.start(this.taskRandom, options);
it'll do a multiple task job Example start task 1 13:05PM stop start task 1 13:10PM start task 1 13:15PM <<< it will double do job like this foreverHere is my code