3

I have override onTaskRemoved in my Service but it never get called when I kill app in device Xiaomi but in SamSung, Sony it get called normally
( I don't set ServiceInfo.FLAG_STOP_WITH_TASK for my Service)

public class MyService extends Service {

    @Override
    public void onTaskRemoved(Intent rootIntent) {
         super.onTaskRemoved(rootIntent);
         Toast.makeText(this,"onTaskRemoved",Toast.LENGTH_SHORT).show();
         Log.i("TAG", "Task removed");
    }
}

I need detect when service stop to start service again because START_STICKY not working like my question here

How can I handle this case. Any help or suggestion would be great appreciated?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Linh
  • 57,942
  • 23
  • 262
  • 279
  • the use brodcast receiver in ondestroy method and again start service – Divyesh Patel Jan 13 '17 at 07:11
  • @Divyesh `onDestroy` will never call **in all device** when we kill app in recent app ^^ – Linh Jan 13 '17 at 07:14
  • `onTaskRemoved` is not guaranteed to be called as I mentioned [here](http://stackoverflow.com/questions/40072294/when-can-ontaskremoved-be-called/40072391#40072391) and [here](http://stackoverflow.com/questions/35729654/whi%D1%81h-function-is-called-when-application-is-removed-from-task-manger/35729793#35729793). _"I need detect when service stop to start service again because `START_NOT_STICKY` not working..."_ No wonder it's not working, use [`START_STICKY`](https://developer.android.com/reference/android/app/Service.html#START_STICKY) instead. – Onik Jan 14 '17 at 02:19
  • Enable Autostart permission for your app in settings – Bibin Johny Jan 25 '19 at 10:02

0 Answers0