Skip to content Skip to sidebar Skip to footer

Background Service Stop When Removing App From Recent

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

Solution 1:

I had same issue with Oppo, Vivo, Mi and etc phones,

  1. after removing from recent applications app was getting killed even services was getting killed

Answer : I had add autostart permissions like this in my application and it worked.

  1. 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

  2. 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.

Solution 2:

Yes, You have to return START_STICKY;

Please refer this link :

https://www.tutorialspoint.com/android/android_services.htm

example :

publicclassMyServiceextendsService {

@Nullable@Overridepublic IBinder onBind(Intent intent) 
{
  returnnull;
   }

   @OverridepublicintonStartCommand(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;

   }

   @OverridepublicvoidonDestroy() {

 super.onDestroy();

Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();

 }
}

Solution 3:

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

Solution 4:

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.

Post a Comment for "Background Service Stop When Removing App From Recent"