OnTaskRemoved () does not receive a call on HUAWEI and XIOMI devices

I used the onTaskRemoved() method in the service to detect when an application was removed from the RECENT device list by brushing it off. I will prepare several protocols and some other operations that should happen when this happens. It works great.

Then I tested this method on a HUAWEI device running Android 6.0. The method is never called. I also added a call to Log.d and, as expected, this log did not appear. The same thing happens on an XIOMI device.

Any ideas why this is happening and how to resolve it? Or is there another way to detect an application that has been removed from the RECENT list without using onTaskRemoved() ?

thank

+27
android huawei service
Nov 17 '16 at 16:32
source share
5 answers

When the user installed your application on the xiaomi device, redirect the user to start automatically and tell the user to turn 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 code above to launch the autoplay activity page on xiaomi

+13
Feb 15 '17 at 7:17
source share

On some devices (some LG, Huawei, Xiaomi, and others), your application must be manually added to the list of “protected applications” or “applications allowed to work in the background” for Android to restart STICKY Services. If your application is not manually added to this list, Android simply kills your processes and does not restart them, nor does it call onTaskRemoved() . This is done to save battery life by limiting the number of applications that STICKY services can run in the background.

On such devices, you should see the page in the "Settings", sometimes under "power management", sometimes in other places where you need to explicitly add the application. You will also need to tell your users to explicitly add your application to this list.

+22
Feb 08 '17 at 17:54 on
source share

I use the onTaskRemoved () method in a service to detect when an application was removed from the RECENT device list by tearing it off.

More illuminated by David Wasser

This is not new for Xiaomi, because Xiaomi has a feature called application resolution, where the user must allow the application to start automatically (Service). In your case, Service not called after it finishes from the stack.

Go this way and enable autorun application:

Settings > permissions > Autostart

+4
Feb 14 '17 at 12:33
source share

In My Huawei, I also encountered a problem, just go to Settings => Energy Saving => Protect Application => find your application and enable it .. The service will start ..

+2
Nov 18 '17 at 8:21
source share

Disclaimer: This is not a good solution .. It's a hack

You can prevent the destruction of the application by the user.

In your Manifest → internal activity tag → Add next line

android: excludeFromRecents = "true"

Your application does not appear in the history of recent applications. Therefore, the user cannot kill the application.

+1
Mar 26 '18 at 10:39
source share



All Articles