flutter_foreground_task icon indicating copy to clipboard operation
flutter_foreground_task copied to clipboard

saveData and getData don't work

Open Kimsangwon0509 opened this issue 3 years ago • 1 comments

i'm following the example and the saveData and getData don't work . can i get help ㅠㅠ

Kimsangwon0509 avatar May 17 '22 05:05 Kimsangwon0509

Confirm it's not working +++

ElKood-Sol avatar Jun 29 '22 19:06 ElKood-Sol

For me it is working the first time. But then i do a stopForegroundService() and a restartForegroundService() and it does not work anymore after that.

GaelleJoubert avatar Nov 07 '22 13:11 GaelleJoubert

For me it is working the first time. But then i do a stopForegroundService() and a restartForegroundService() and it does not work anymore after that.

I use this way to walk around the problem:

  1. call stopService() first.
  2. delay a little while.(I don't like this way, but it is needed.)
  3. saveData and startService(not restart service).
if (await FlutterForegroundTask.isRunningService) {
      await FlutterForegroundTask.stopService();
      await Future.delayed(Duration(milliseconds: 100));
    }
..........
await FlutterForegroundTask.saveData(
        key: 'json', value: json.encode(data.toJson()));
        
bool reqResult = await FlutterForegroundTask.startService(
      notificationTitle: '${data.name}',
      notificationText: '${formatSeconds(data.value)}',
      callback: startCallback,
    );

pyjserv avatar Nov 09 '22 03:11 pyjserv

For me it is working the first time. But then i do a stopForegroundService() and a restartForegroundService() and it does not work anymore after that.

I use this way to walk around the problem:

1. call stopService() first.

2. delay a little while.(I don't like this way, but it is needed.)

3. saveData and startService(not restart service).
if (await FlutterForegroundTask.isRunningService) {
      await FlutterForegroundTask.stopService();
      await Future.delayed(Duration(milliseconds: 100));
    }
..........
await FlutterForegroundTask.saveData(
        key: 'json', value: json.encode(data.toJson()));
        
bool reqResult = await FlutterForegroundTask.startService(
      notificationTitle: '${data.name}',
      notificationText: '${formatSeconds(data.value)}',
      callback: startCallback,
    );

Thanks for the tips ! :)

GaelleJoubert avatar Nov 09 '22 08:11 GaelleJoubert