1 min readJun 11, 2019
Can you try on different devices and see your results. Its really hard to get it correct when working with background tasks. You can even find the issue is not in your code, because different devices behave differently and the behavior changes from manufacturer to manufacturer.
Also check this documentation on Broadcast Receivers. It may be an eye opener.
Foreground is the closest to a working solution that you can get