I have a Service in which the onTaskRemoved()
method has been implemented.
When the service is started with startService()
the function onTaskRemoved()
is called when the app is removed from the recent-apps-list by swipe.
But if the service is started with bindService()
, then onTaskRemoved()
never called.
How can I make the Service call onTaskRemoved()
when app removed from recent-apps-list by swipe after it has been started with bindService()
?
Android calls the following lifecycle methods if started with:
1. bindService():
Activity﹕ onCreate()
CustomService﹕ onCreate()
CustomService﹕ onStart()
CustomService﹕ onStartCommand()
CustomService﹕ onBind()
// Here we swipe to remove app from recent-apps-list
CustomService﹕ onTrimMemory()
2. startService():
ActivityA﹕ onCreate()
CustomService﹕ onCreate()
CustomService﹕ onStart()
CustomService﹕ onStartCommand()
CustomService﹕ onBind()
// Swipe to remove app from recent-apps-list
CustomService﹕ onTrimMemory()
CustomService﹕ onTaskRemoved() // <=====
CustomService﹕ onUnbind()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…