Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] javascript – react-native-background-timer inconsistently works on Android for recording audio

Posted on November 11, 2022 By

Solution 1 :

You will have around ~40 seconds to call your function and call the completion handler in the background state or phone is in the sleep state.

If you don’t finish it on time, iOS will kill your app. If you don’t obey the rules, iOS will give you less chances to wake up. For more detailed usage of Background Modes, you may check following tutorial

It is due to app developers abusing this mechanism, killing their customers’ device battery.

Note: Watchdog Timeout is ~40 sec.

Problem :

I am using BackgroundTimer from react-native-background-timer in a React native project for Android.

I want a user to be able to record audio after a set duration (e.g. record for 5 minutes after 30 minutes).

The issue I have is that it works “sometimes”. It seems the OS is often killing the process – especially if the time to execute is longer.

Code extract:

import BackgroundTimer from 'react-native-background-timer';
...

// Start a timer that runs once after X milliseconds
const timeout1 = BackgroundTimer.setTimeout(() => {

    // Should work when when app is the the background
    this.onStartRecord();

    const timeout2 = BackgroundTimer.setTimeout(() => {
        this.onStopRecord();
        BackgroundTimer.clearTimeout(timeout2);
    }, millisRecording);

    // Clear first timeout
    BackgroundTimer.clearTimeout(timeout1);

}, millisUntilRecordMoment);

Thes rest of the code is here: https://github.com/bentaly/listen/blob/master/App.tsx

I have also tried building this in Expo previously which didn’t work.

Is there anyway to guarantee this operation will work?

Comments

Comment posted by Ben Taliadoros

Hi Muhammad, did you mean to link an article? Also this question specifically asked about Android

Comment posted by Muhammad Numan

“It seems the OS is often killing the process – especially if the time to execute is longer.” it seems of ios question

READ  [FIXED] geolocation - is there any way to read "select mock location app" from Android developer settings?
Powered by Inline Related Posts

Comment posted by Ben Taliadoros

OS stands for operating system, such as iOS, Android, Windows, Linux etc

Comment posted by Muhammad Numan

@BenTaliadoros there was the same issue on ios, he played silent 1-second audio every 8 seconds to prevent killing the process. but he said I got this issue on android only Huawei devices

Comment posted by Ben Taliadoros

I will but I won’t be able for a few days, if it works I’ll let you know and you can update as a separate answer

Android Tags:android, ecmascript-6, javascript, react-native

Post navigation

Previous Post: [FIXED] java – android studio 4.0 cannot load jdk class
Next Post: [FIXED] java – How can ViewParent be cast into View?

Related Posts

[FIXED] android – RazorpayFlutterPlugin in class RazorpayFlutterPlugin cannot be applied to given types; Android
[FIXED] android – Delphi 11.1 crash staring Foregound Service Android
[FIXED] android – Return type of ‘getItem’ is not a subtype of the return type of the overridden member ‘@NonNull public abstract fun getItem(p0: Int)’ Android
[FIXED] android – How Flutter MethodChannel works, and how it is different from Interop? Android
[FIXED] android – I want to achieve the below layout, the button should be at the bottom of the screen, when the lazy column is filled, the button shouldn’t go outside Android
[FIXED] java – Unable to toggle switch to on mode in List View in android studio Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme