📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

react-native-background-timer-android

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-background-timer-android

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

1.0.4
latest
Source
npm
Version published
Weekly downloads
293
-20.81%
Maintainers
1
Weekly downloads
 
Created
Source

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

import Timer from "react-native-background-timer-android";

// Start a timer that will repeatedly log "tic" after 500 milliseconds
const intervalId = Timer.setInterval(() => console.log("tic"), 500);

// Cancel the timer when you are done with it
Timer.clearInterval(intervalId);

// Start a timer that will log "tic" after 500 milliseconds just once
const timeoutId = Timer.setTimeout(() => console.log("tic"), 500);

// Cancel the timer if needed
Timer.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>;

Keywords

react-native

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts