You need to whitelist your app in the one plus settings. Chinese manufacturers block apps from running in the background. You would face a simillar situation in Xiaomi, Vivo, gionee, Oppo etc.
As for Xiomi ...go the security app ..auto start and allow your app to run in the background. This is a device specific thing and there is no code solution to it. You have to manually enable it. Hope it helps!