0

I'm here developed a hybrid cordova based android app in which i need to do some task before killing app for this i wrote below code onDestroy() in MainActivity and onTaskRemoved in one of service class which is calling perfectly on Samsum, Motorola, Asus etc. many device except Redmi MI Devices.

Some days back the same code was working in MI device but now its not after updating MI with MIUI 9.6.0 and above. I have tested one of MI device with MI 9.5.0 in which its working both the method but after upgrade of my device now its not working.

So is someone having the same issue? what we can do to achieve app killing event? is there any option through which it should start working or having any other way to do the same only for MI device?

I have checked over the internet and did changes for Autostart options as well still not working.

@Override
    public void onTaskRemoved(Intent rootIntent) {
        Log.d(getClass().getName(), "App just got removed from Recents!");
        Toast.makeText(getApplicationContext(),"18. onTaskRemoved()", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(getApplicationContext(),"16. onDestroy()", Toast.LENGTH_SHORT).show();
    }
Zoe
  • 27,060
  • 21
  • 118
  • 148
Surya
  • 171
  • 1
  • 1
  • 10

1 Answers1

2

Few OEMs including (RedMi) customizes the stack ROM for battery/memory optimization and have blocked the "onDestroy()" and "onTaskRemoved" callbacks. As an user you can prevent the App's service from killing by locking the App. Or, White listing the app by enabling "Autostart" setting for the App. Programmatically you can prompt the user to enable the Autostart for the App: Please find details here

Please note: I have tested the Autostart enabling programatically on few devices but found that it does not works always. So not sure how to fix in a proper way, but this solution might worked at-least up-to certain extent.

Akki
  • 775
  • 8
  • 19