I found some questions/answers on how to track when the app goes to the background, like this one: Run code when Android app is closed/sent to background
But I need to run the code only if the user actually closes the application.
To exemplify:
- The user clicks on the Overview button;
- The Android opens the list of thumbnail images of the recent apps;
- The user swipe the thumbnail of my app to remove it (here is where I need to run the code).
I tried to add some code to the OnDestroy()
method, but it don't seem to be called when I do steps above. I know the code works because I've done a test where I call the Finish()
right at the start of my OnCreate()
, then the OnDestroy()
is called and so my code.
I'm using Xamarin and MvvmCross, but Java code is welcome too.