BackgroundActions.stop does not terminate ongoing task

Aperta
#201 5 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, react-native
Ambito
backend, mobile

Direzione di ricerca

Start by reading the task lifecycle and stop implementation in the library, then trace how the task function handles completion or cancellation. The report includes a JavaScript example but no failing test or specific library files. Done means reproducing the ongoing task and confirming that calling BackgroundActions.stop terminates it.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

stop not working

import BackgroundActions from 'react-native-background-actions';
import { DeviceEventEmitter } from 'react-native';

/**
 * Class BackgroundTaskManager is designed to manage background tasks using
 * react-native-background-actions. However, the task started by scheduleTask
 * does not stop when finish is called.
 */
class BackgroundTaskManager {
  static instance = null;
  static iteration = 0;
  static backgroundTaskId = null;

  constructor() {
    if (!BackgroundTaskManager.instance) {
      BackgroundTaskManager.instance = this;
      BackgroundTaskManager.resetInit();
      console.log('BackgroundTaskManager initialized');
    }

    return BackgroundTaskManager.instance;
  }

  /**
   * Resets the task manager and clears any existing background task configuration.
   */
  static resetInit() {
    this.configArgsiOS = null;
    this.configStartFunction = null;
    this.configTimeoutFunction = null;
    this.task = null;
    this.options = null;
    this.iteration++;
    console.log('BackgroundTaskManager reset');
  }

  /**
   * Configures the task manager with provided arguments.
   */
  static async configure(...args) {
    BackgroundTaskManager.resetInit();
    console.log('Configuring with args:', args);
    this.configArgsiOS = args;
    if (this.configStartFunction === null) {
      this.configStartFunction = args[1];
    }
    this.configTimeoutFunction = args[2];
    console.log('Configuration is now unified for both platforms.');
  }

  /**
   * Schedules a new background task. The task does not stop as expected when
   * the finish method is called.
   */
  static async scheduleTask(...args) {
    const { taskId } = args[0];
    console.log('Scheduling task with args:', args);

    // Task scheduling options
    this.options = {
      // ... existing options
    };

    // Task logic
    const veryIntensiveTask = async taskDataArguments => {
      // ... existing task logic
    };

    console.log(`Background task ${taskId} scheduled`);
    if (this.configStartFunction) {
      BackgroundActions.start(veryIntensiveTask, this.options);
    }
  }

  /**
   * Attempts to stop the background task. However, this does not
   * seem to stop the ongoing task.
   */
  static async finish() {
    BackgroundActions.stop();
    BackgroundTaskManager.resetInit();
    console.log(`Stopping background task`);
    DeviceEventEmitter.emit('stopBackgroundTask');
  }

  static delay = ms => new Promise(resolve => setTimeout(resolve, ms));
}

export default BackgroundTaskManager;

tried all ways but my internal hidden logic when i cann BackgroundActions.stop does not terminate ongoing task

Lingua principale
Java
Stelle
941
Fork
145
Merge medio
1g 23h
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Rapsssito/react-native-background-actions

Tutte le issue di Rapsssito/react-native-background-actions

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.