Search code examples
androidservicehuawei-mobile-services

onTaskRemoved() not getting called in HUAWEI and XIAOMI devices


I've been using onTaskRemoved() method in a Service to detect when an app was removed from device RECENT list by swiping it away. I preform some logging and some other operations that need to take place when this happens. It works perfectly.

Then I checked this method in an HUAWEI device running Android 6.0. The method never gets called. I also added a Log.d call and as expected, this log never appeared. The same happens on a XIAOMI device.

Any ideas why this happens and how to resolve this? Or is there another way to detect app was removed from RECENT list with out relying on onTaskRemoved() ?

Thanks


Solution

  • 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