Git Product home page Git Product logo

react-native-background-timer-workmanager's Introduction

React Native Background Timer Workmanager [Android]

Emit event periodically in both foreground and background.

Installation

  1. If you use Expo to create a project you'll just need to "eject".

    expo eject
  2. Install React Native Background Timer Work Manager package.

    yarn add react-native-background-timer-workmanager
    # or using npm
    npm install react-native-background-timer-workmanager --save
  3. Link React Native Background Timer library. This step is not necessary when you use React Native >= 0.60 (and your app is not ejected from Expo).

    react-native link react-native-background-timer-workmanager
  4. Link the library manually if you get errors:

Android manual linking
  • android/settings.gradle

    + include ':react-native-background-timer-workmanager'
    + project(':react-native-background-timer-workmanager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer-workmanager/android')
  • android/app/build.gradle

    dependencies {
    +   implementation project(':react-native-background-timer-workmanager')
    }
  • android/app/src/main/java/com/your-app/MainApplication.java

    + import com.shubhamd99.timer.BackgroundTimerPackage;
    
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
    +   new BackgroundTimerPackage()
      );
    }

Usage

import BackgroundTimer from 'react-native-background-timer-workmanager';
BackgroundTimer.start(3000, 'UNIQUE_TAG' () => { 
// code that will be called every 3 seconds 
});

BackgroundTimer.stop('UNIQUE_TAG'); // To Stop Polling

Example:

import React, {useEffect} from 'react';

const App = () => {
    useEffect(() => {
        BackgroundTimer.start(10000, 'homeScreenPolling', () => {
            console.log('polling..');
        });
        return () => BackgroundTimer.stop('homeScreenPolling');
    }, []);
};

export default App;

react-native-background-timer-workmanager's People

Contributors

shubhamd99 avatar

Stargazers

peacecoder avatar

Watchers

 avatar  avatar

react-native-background-timer-workmanager's Issues

Delay is not working

I setup a background timer but the callback is not running according with the time specified

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.