Many of our errors in production are caused
by the alarm module finishing. In devices after
android version 7 we are "required" to use
startForegroundService or else the following
error supposedly occurs:
Exception java.lang.IllegalStateException:
at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1725)
at android.app.ContextImpl.startService (ContextImpl.java:1680)
at android.content.ContextWrapper.startService (ContextWrapper.java:731)
at android.content.ContextWrapper.startService (ContextWrapper.java:731)
at com.massive.AlarmModule$getTimer$1.onFinish (AlarmModule.kt:144)
at android.os.CountDownTimer$1.handleMessage (CountDownTimer.java:127)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:236)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228)
at java.lang.Thread.run (Thread.java:923)
I say supposedly because on all of my testing
devices (which are android 7+) this error
doesn't occur.
Related to #142.
Can't be sure this fixed anything because I can't replicate the error
on my emulators running android 13. I need to install android 13
on a real device and try replicate + see if this fixes it.
This was supposed to solve the timer stopping sometimes
when the application was in the background.
It was actually stopping because of battery optimizations.