Service | How to detect if application get killed from task manager in android

Pic 1: Task Manager
We always see that after successful exit from a application by
pressing back button or send app to background by pressing
home button. Application get lilted to
Task manager just like below image Pic 1.
We can also avoid our app to get listed out
to task manger by using a tag in
android_manifest.xml file's <application> tag.

"android:excludeFromRecents="true""
 <Application ... android:excludeFromRecents="true"
      <Service  android: name = ".ExampleService"  /> 
      ... 
  </ Application> 


Can we also detect that Our app has killed from task manager?
Then Answer is yes we can get this information as well .
But we have to create a  Service  .


We can also detect if our app get swipe out from task manager by overriding "onTaskRemoved()" in  Service  class by extending it to child class.  If our app swipe out from task manager then service call comes in  onTaskRemoved method.

 class ExampleService extends Service{  
 @override  
 private void onTaskRemoved(Intent rootIntent){  
 //to something here  
 }  
 }  

Please feel free to comment and share your reviews to me.


Previous
Next Post »