Ontaskremoved() Not Getting Called in Huawei and Xiaomi Devices

onTaskRemoved() not getting called in HUAWEI and XIAOMI devices

When user has installed your app on xiaomi device, redirect user to auto start activity and tell user to switch on:

if (Build.BRAND.equalsIgnoreCase("xiaomi")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent);
}

Use the above code to launch autostart activity page on xiaomi

onTaskRemoved() not getting called when Home press & kill the app

Based on your use case, you should be able to meet the criteria for the White listing on Android N and above. You can follow this link to Whitelist your app. By requesting this permission, you can relax some restrictions (like accessing network or holding partial lock) implied by Doze mode and Android O. These restrictions are imposed by OS on the app those are not white-listed.

For Lollipop: Certain manufacturers using cyanogenmod or other custom implementation, could have impact on the intended behavior of START_STICKY. Workaround in this case would be to rely on onDestroy() method of service to:

  1. Restart the service.
  2. Trigger an AlarmManager which will trigger after few seconds and start the service.

If you use approach 2:

On normal devices where the START_STICKY behaves as intended, you can use the AlarmManager to check if service is running by:

  1. Maintain a static variable in service to check if service has been started
  2. Cancel the AlarmManager onStartCommand() of the service.

Service: onTaskRemoved not called if started with bindService

A service can be bound or started or both. It depends on how you implement onStartCommand and onBind say the docs.

http://developer.android.com/guide/components/services.html

But if you want your service to do both stay around and talk with clients over an IBinder then simply start the service and then bind to it.

startService(new Intent(context, CustomerService.class));
// Bind to the service
bindService(new Intent(context, CustomerService.class),
mConnection, Context.BIND_AUTO_CREATE);

Edit 20220314. "future versions of the os" may end the service when it doesn't have a notification card for the user to interact with the service.

...
lots have changed since I answered this I got a recent vote so here I am. You want your service to run in the background have a notification going and a way for the user to interact with the service in the notification. You've seen them the play pause controls on music and video notifications. Without a notification the os might end your service.



Related Topics



Leave a reply



Submit