Skip to content

Repository files navigation

react-native-background-timer-android

This library provides setTimeout and setInterval implementations that keep working even if the app is running in the background or the screen is locked.

Based on react-native-background-timer but with major code changes and only works on Android.

Features

  • Clear and simple API
  • Can set multiple timers
  • Keeps running when the screen is locked
  • Each timer has its own WakeLock that remains active while it's running
  • Intervals are handled entirely on the native side
  • Fault-tolerant: any exception gets reported back to JS via promises
  • TypeScript declarations included

Install

yarn add react-native-background-timer-android

Usage

importTimerfrom"react-native-background-timer-android";// Start a timer that will repeatedly log "tic" after 500 millisecondsconstintervalId=Timer.setInterval(()=>console.log("tic"),500);// Cancel the timer when you are done with itTimer.clearInterval(intervalId);// Start a timer that will log "tic" after 500 milliseconds just onceconsttimeoutId=Timer.setTimeout(()=>console.log("tic"),500);// Cancel the timer if neededTimer.clearTimeout(timeoutId);

API

Timer.setInterval(callback: ()=>void,millis: number,onError?: (error: Error)=>void): number;Timer.setTimeout(callback: ()=>void,millis: number,onError?: (error: Error)=>void): number;Timer.clearInterval(id: number): Promise<void>;Timer.clearTimeout(id: number): Promise<void>;

About

setInterval and setTimeout that works even if the app is running in the background

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages