On Xiaomi or Oppo or Vivo phones - Application Task not working as expected

1.4k views Asked by At

I have a small android application project (Used for a local community news app)on android, which is (or was) working on API 22 and onward. Only a issue recently came to our notice is that on Chinese phones like Xiaomi or Oppo or Vivo our notifications (tried both local/Firebase) are not working even when the application is white-listed.

I see some suggestions on online blogs to use AlarmManager (but I guess this is bad idea - for real time notifications), not sure

I have also tried trading on code like below, but still no luck

https://github.com/commonsguy/cw-omnibus/tree/v8.4/Notifications/Foreground

What I've figured out is, if the app task is locked, it will be persisted and my app notification work.

See the image below:

enter image description here

How to programmatically achieve this?

Can it be a single code (or module) for all the versions of Xiaomi or Oppo or Vivo (or say MiUI)?

1

There are 1 answers

0
Madhur Jain On

Yes i also faced this problem, i have tried many given solutions in oppo and vivo mobiles but problem still not solved.

did you try onTaskRemoved() method in Service class? when we swipe app or kill the app onTaskremoved() method is called instead of onDestroy() of Service class.

So maybe there is a solution if we send a broadcast receiver in this method which restart the Service.

And also look this thread also:

How to enable auto start for my app in xiaomi programmatically

Maybe it helps.