BJW
BJW

Reputation: 1095

Flutter background task when app is being used

This question is about the flutter framework.

I am looking for information about how to schedule background tasks in the app while the app is being used by the user. It is not necessary to run the task also when the whole app is in the background / closed.

To explain, an example: User starts the app and goes to a news article. The page is finished rendering and the user starts reading. While the user is reading I want the app to do tasks in the background such as checking whether there is new data that can be written to the database or maybe that avatar's from other user have update and it should be updated on the user's phone.

Does anybody know where to look for this?

Upvotes: 0

Views: 660

Answers (1)

AVEbrahimi
AVEbrahimi

Reputation: 19214

If it's a simple task, you may use Timer:

https://api.flutter.dev/flutter/dart-async/Timer-class.html

But it can't broadcast messages, so you should either use a provider or if it's time-critical and it's a heavy task you should use isolates:

https://api.flutter.dev/flutter/dart-isolate/Isolate-class.html

If you are unfamiliar with isolates you can use ready-made packages, like this one : https://pub.dev/packages/flutter_isolate

Upvotes: 1

Related Questions