react-native-background-timer icon indicating copy to clipboard operation
react-native-background-timer copied to clipboard

Timer stops on android after sometime running in background

Open ramzihere opened this issue 4 years ago • 19 comments

Using BackgroundTimer.setInterval in the app it's working fine while the app in the foreground. When the app state changes from foreground to background it works fine there for a while as well but after few minutes like 15 to 20 it stops. Also while changing the app state from background to foreground app killed/refreshed(crashes) as well.

any help will be appreciated. Thank you

ramzihere avatar Jun 28 '21 12:06 ramzihere

I'm having the same problem. When the app is in the background, after like 8 minutes the timer stops working and when I bring it back to the foreground it reloads.

amduffy19 avatar Jul 15 '21 19:07 amduffy19

I am facing the exact same issue

mmilad75 avatar Jul 15 '21 21:07 mmilad75

same issue,

ztaz311 avatar Jul 19 '21 12:07 ztaz311

i am also facing same issue , any solution pls

Amar-RN avatar Jul 21 '21 05:07 Amar-RN

i am also facing same issue on android on iOS its working fine

huzaifa-umer avatar Aug 04 '21 07:08 huzaifa-umer

@huzaifa-umer @Amar-RN Did you guys found the solution, I am also having the same issue , and for IOS , the timer stops after 30s , are you guys also facing this issue of timer stopping after 30s in IOS or not ?

kirantripathi avatar Aug 09 '21 09:08 kirantripathi

pls tell me how to fix it

On Wed, 4 Aug 2021 at 12:54, huzaifa-umer @.***> wrote:

i am also facing same issue on android on iOS its working fine

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/337#issuecomment-892429299, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATU7BUBBKNQ6AAOT3M74QBTT3DTJ7ANCNFSM47N4F45Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Amar-RN avatar Aug 09 '21 09:08 Amar-RN

@huzaifa-umer @Amar-RN Did you guys found the solution, I am also having the same issue , and for IOS , the timer stops after 30s , are you guys also facing this issue of timer stopping after 30s in IOS or not ?

You have to on background mode capability in Xcode and enable Audio Airplay option to run audio in background

https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_ios_and_tvos/enabling_background_audio

huzaifa-umer avatar Sep 08 '21 06:09 huzaifa-umer

same issue on Android - when the app is in the background, after 8 minutes the timer stops working and the app is killed

jzamarioli avatar Sep 12 '21 12:09 jzamarioli

Hello, When in the Background, The timer stops & the app crashes exactly 10 minutes after putting it in the background (after minimizing), Got any solution? or workaround for this issue?

ganarajss avatar Jan 15 '22 15:01 ganarajss

Same issue on iOS. Curious if anyone found a solution or workaround? Thanks!

alexlod avatar Aug 07 '22 03:08 alexlod

Looks like iOS has gotten more aggressive with killing background tasks and hence this library doesn't work so well anymore. See https://rossbulat.medium.com/react-native-background-task-management-in-ios-d0f05ae53cc5 for more details.

alexlod avatar Aug 11 '22 18:08 alexlod

I have a same issue on Android. API > 29 React-native: 0.66.2

leonidlewis avatar Apr 07 '23 02:04 leonidlewis

Same issue here, any solution?

ReddyyZ avatar Feb 18 '24 18:02 ReddyyZ

I've resolved this issue

On Sun, Feb 18, 2024 at 8:03 PM Arthur Oliveira @.***> wrote:

Same issue here, any solution?

— Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/337#issuecomment-1951400937, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT3NYX6ZBJLU4EONFIXFZN3YUI67VAVCNFSM47N4F452U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJVGE2DAMBZGM3Q . You are receiving this because you commented.Message ID: @.***>

leonidlewis avatar Feb 18 '24 18:02 leonidlewis

I've resolved this issue On Sun, Feb 18, 2024 at 8:03 PM Arthur Oliveira @.> wrote: Same issue here, any solution? — Reply to this email directly, view it on GitHub <#337 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT3NYX6ZBJLU4EONFIXFZN3YUI67VAVCNFSM47N4F452U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJVGE2DAMBZGM3Q . You are receiving this because you commented.Message ID: @.>

Can you post your solution please

ReddyyZ avatar Mar 23 '24 19:03 ReddyyZ

Any updates?

ReddyyZ avatar Apr 19 '24 17:04 ReddyyZ

On Android, this is due to the use of PostDelayed(), It's cancelled after some time in the background or if the main thread is destroyed.

AlarmManager could be used to avoid this, but there are some disadvantages:

  • It may cause greater battery consumption depending on the frequency.
  • Need to ask user to grant SCHEDULE_EXACT_ALARM permission.

WorkManager could also be used, but does not guarantee that the task will be executed at the specified time.

josegiufrida avatar Jul 17 '24 14:07 josegiufrida