I use the following code to create some temp files, and wrapped tem as inputsteam to send to client side.
I understand that the temp files can be deleted automatically b
First, keep in mind that "exit" for an Android app means something very different than it does for a desktop application. See this article for details, but the short answer is that, in general, you have no idea when the OS is actually going to close your app (even if it's not visible). In fact, there isn't an explicit guarantee that the OS will close it at all.
A few ideas can be found here (it's C#/Xamarin.Android but same exact idea for Java): How to detect application exit on android?
In addition to the stuff listed there, you could also try registering broadcast receivers for when the phone's shutting down.
Another (worse, in my opinion) way is to simply do this when the app becomes no longer visible (in onStop
). As noted above, however, this isn't the same thing as the program actually closing (because you don't know when - or even if - the OS will actually close the app).