Abi86
Abi86

Reputation: 1

Repeat a function every one minute in background with flutter

I'm writing an app with flutter to communicate with a weather station. The smartphone/tablet have to send via usb a command every one minute, recieve data from the station, and then send this data in a Firebase database.

I know that a smartphone is not the best device for do this, but I'm using an old device and I don't care about battery health (maybe a raspberry could be a better solution).

I'm using usb_serial package to communicate via usb and cron package for timing the events. And all works fine.

The problem is that the app have always to run in foreground. The first solution that i tried is using two apps: (1) one that keeps the screen on (2) and another that makes the screen black to reduce the energy consumpion. This is not the best solution.

I think that a better way is to use a background execution. I made some attempts with workmanager package but the minimum frequency is 15 min, with android alarm manager package but I'm not sure that wakes up also the network connection.

Anybody can suggest me witch is the best way to achieve my goal?

Thanks.

Upvotes: 0

Views: 3113

Answers (1)

Abdul Malik
Abdul Malik

Reputation: 1188

Refer this answer https://stackoverflow.com/a/14946013/13892187

In Dart for setting a recurring function we use the Timer class

Upvotes: 1

Related Questions