Background service is stop, when removing my app from recent in oppo & vivo mobiles, & Broadcast reciever also not working in that case.
Background Service Stop when removing app from recent
4.7k views Asked by Yogesh Choudhary Paliyal At
4
There are 4 answers
1
On
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.
1
On
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();
}
}
I had same issue with Oppo, Vivo, Mi and etc phones,
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.