1

I want to know when user swipe to close app in recent list, but I haven't found any methods yet. onDestroy and onTaskRemoved are not ALWAYS called, they depend on system or device.

So, which methods will be surely called when app closed, and I can use it in all devices?

Qk Lahpita
  • 427
  • 2
  • 10
  • 18

1 Answers1

0

OnPause(), is the method that is called everytime your app goes in background or losses it focus. So if you want your working to be done after the application losses it's focus use this method. Otherwise take a look at This answer and activity life cycle for more info.And as described in the answer above use Logs to identify which methods are ran in every device and then use them.

https://developer.android.com/guide/components/activities/activity-lifecycle.html

Umair
  • 6,366
  • 15
  • 42
  • 50
  • thanks but I only want to detect when user CLOSE app by swipe it from recent task, not when app in background – Qk Lahpita Dec 12 '17 at 10:36
  • @QkLahpita yes in that case onStop() is called maximum number of times before completely destroying the activity, but still as you mentioned there are some cases in which this method doesn't get called. So onPause is the only one i found on which we are sure that it will be called. Moreover you can add logs and check which methods is being called maximum number of times. :) – Umair Dec 12 '17 at 10:39