What's the correct way of passing data/props to TaskManager/BackgroundFetch

Please provide the following:

  1. SDK Version: ~45.0.0
  2. Platforms(Android/iOS/web/all): Android
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I’m building a bus transportation app where users can subscribe to the arrival time of a certain bus.

Basically, the user should be able to subscribe to some bus’s arrival time and get notifications every minute.

I made it using the expo-notifications, but I also want it to be able to work in the background.

I tried using the TaskManager and BackgroundFetch, but documentation doesn’t explicitly provide a way to pass props/data to a defined task.

Basically the flow should work like this:

User opens app → subscribes to bus #55 → should receive a notification about bus #55’s arrival time every minute in background.

I’m struggling with the part of passing the bus number to the task.

If you want BackgroundFetch to work based on a particular piece of user-defined data, you would want to store that data in a global location (e.g., in AsyncStorage), and then have a single background task registered that reads the data from that global location and performs the corresponding tasks.

In this particular case, it’s likely you’ll be better-served by not using a background task at all, but rather sending notifications from a server. The mobile OS tends to limit how often a task can run in the background, and once per minute may be too often.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.