问题
What I want to do is to know when user closes the app from Android Launcher's menu, which gets opened on home button long click:
I want to do some operations when user closes the app.
Actually, I want user to logout each time he leaves the app, but as long as he can close app in this was too, I have to handle this event and then make my operations.
I've tried to google this one, but I couldn't find anything considering this.
I don't want to override onStop() or onDestroy(), as long as the user may come back to the app then, in that case I don't have to make my changes. Don't advice this. I only want to make changes, when user closes app entirely.
So my questions are:
Isn't there anything like
onApplicationDestroy()
?Is it possible to make connection with server and pass some values when user closes app in this way?
回答1:
I want to do some operations when user closes the app.
That is not possible. Your process is simply terminated, with no notice.
Isn't there anything like onApplicationDestroy()?
No.
Is is possible to make connection with server and pass some values when user closes app in this way?
No.
Note that there is nothing significantly different between the user swiping your app off the recent-tasks list (what you depict in your question) and various other scenarios, including:
Android terminating your background process to free up memory for other applications
Users terminating your background process using a third-party task maanger
来源:https://stackoverflow.com/questions/17297303/handle-app-closing-event-from-launchers-menu