skip to Main Content

I am developing a fitness app in react native.

I want to develop a rest timer feature for users to use to set rest time between workouts.

When the rest time ends, I want to send the user a local notification.

To make sure the user receives the notification even when the app in not in the foreground in Android, should I try to implement Android’s Foreground Service? or WorkManager?

I have read the documentation and have seen some youtube videos on this but am not sure..

What would make sure the users get the notifications without the OS delaying them?

2

Answers


  1. AlarmManager should be used for precise alarms.

    Unlike WorkManager, AlarmManager wakes a device from Doze mode. It is therefore not efficient in terms of power and resource management. Only use it for precise alarms or notifications such as calendar events — not background work.

    See Set an exact alarm for details.

    Login or Signup to reply.
  2. As like @user18309290 said AlarmManager is the best choice to do it.
    I recommend to use react-native-push-notification.
    You don’t need other steps in installation specifically to implement only local notification.

    PushNotification.localNotification({
    ...
       when: null, // (optional) Add a timestamp (Unix timestamp value in milliseconds) pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
    ...
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search