Background service is stop, when removing my app from recent in oppo & vivo mobiles, & Broadcast reciever also not working in that case.

- 604
- 1
- 8
- 23
-
6Very nice to know. Thank you. – greenapps May 31 '18 at 11:02
-
Bad day, isn't it ? – Jan Černý May 31 '18 at 11:28
-
i don't understand why companies change the functionality of basic codes – Yogesh Choudhary Paliyal May 31 '18 at 11:43
-
1Mostly because they want their phones to excel in battery consumption, users will judge their company for battery consumption and not how well an app runs on it – Suhaib Roomy May 31 '18 at 12:53
-
https://stackoverflow.com/a/40261311/3290339 – Onik May 31 '18 at 19:35
-
1please post your manifest – David Wasser Jun 06 '18 at 11:52
-
thanks for your response but, now issue is resolved. :) – Yogesh Choudhary Paliyal Jun 06 '18 at 11:55
-
2How have to resolved issue. I am facing same problem in broadcast receiver – Sachin Singh Jul 09 '18 at 12:08
-
allow app to auto start & put a alarm manager that hit every minute & triger a broadcast reciever programatically – Yogesh Choudhary Paliyal Jul 09 '18 at 13:01
-
1@YogeshPaliyal Is your solution work on latest Android versions too? Isn't Alarm Manager having issues in latest Android versions? – venkat Aug 04 '18 at 09:56
4 Answers
I had same issue with Oppo, Vivo, Mi and etc phones,
- after removing from recent applications app was getting killed even services was getting killed
Solution: I had add autostart permissions like this in my application and it worked.
After resolving this issue my app was getting frozen/killed after sometime running in background due to DOZE mode Solution: for this condition this worked and now my app is working in background in any device
After above things do this:
intent.setClassName("com.coloros.oppoguardelf", "com.coloros.powermanager.fuelgaue.PowerConsumptionActivity"); startActivity(intent);
call above intent, it will redirect you to battery option, "Disable Background Freeze, Abnormal Apps Optimization and Doze from \"Energy Saver ->youAPP"
Note: Once you call above intent, there you may get different options to turn off Battery saving options.

- 2,129
- 3
- 25
- 53
-
it is not working for me in Vivo devices. can you please help me? – Pooja Shukla May 15 '19 at 16:17
-
Sure, Please mention the device which you are using, then I can help further – Amin Pinjari May 16 '19 at 04:15
-
-
-
-
Sadly is that this might be working on some devices but still not working on OPPO devices, I've tested on OPPO A1601 running Android 6.0(ColorOS 3.0). Even though I have whitelisted the app in "AutoStart" and "PowerSaving", when I call `isIgnoringBatteryOptimizations()`, it still always return a false, and If I remove the app from the recent list it still gets killed. The weirdest thing is that the page `Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS` doesn't exist! It seems like OPPO is not following standard about "DOZE mode" and they just kill anything from recent Apps brutally. – Lynch Chen Mar 07 '21 at 07:03
Yes, You have to return START_STICKY;
Please refer this link :
https://www.tutorialspoint.com/android/android_services.htm
example :
public class MyService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}

- 200
- 7
-
the devices mentioned in question behaves differently, for this START_STICKY doesnt work, solution I have mentioned as a answer – Amin Pinjari Jan 29 '19 at 15:43
yes.
if you want the service to start over you need to configure it as 'sticky':
https://developer.android.com/reference/android/app/Service.html#START_STICKY
After doing this, follow the accepted answer, it will work.

- 2,129
- 3
- 25
- 53

- 238
- 1
- 10
-
the devices mentioned in question behaves differently, for this START_STICKY doesnt work, solution I have mentioned as a answer – Amin Pinjari Jan 29 '19 at 15:43
You need to ask your users to whitelist your app in their settings for it to work in these phones. The custom OS on these phones only allows whitelisted apps like whatsapp,fb etc to work in background, other apps have to whitelisted manually from settings

- 2,501
- 1
- 16
- 22