0
votes

I'm developing a flutter app which requires to run background task approximately every 5 minutes. To achieve this I tried using libraries like background_fetch doing everything within the phone, but it doesn't fit my needs. I wonder if there was a server way to silently awake the app every 5 minutes, even for a short period of time in order to execute the needeed piece of code

1

1 Answers

1
votes

Maybe subscribing your app to a stream and listening for changes is what you want, firebase makes this super easy, but i dont know if you want to execute the code manually or you are just checking if there was some change on the server.

this listens to some messages in your firestore collection and when whatever you are listening to changes, it will trigger the action of fetching the data on your app

final _firestore = FirebaseFirestore.instance; 

void messagesStream() async {
await for (var snapshot in _firestore.collection('messages').snapshots()) {
  for (var message in snapshot.docs) {
    print(message.data());
  }
 }
}

If this is not what you want you can check firebase cloud messaging and every 5 minutes send data to the phone https://firebase.google.com/docs/cloud-messaging/