0

when someone closes my application by swiping it off, i would like to send a message to a server (in this case, another phone that is working as a hotspot).

The problem is that i can't figure out what method gets called when someone does that. I tried onDestroy(), but it doesn't always get called, only works sometimes, i guess it deppends on the memory resources, etc.

I need to inform the server when a client leaves.

Does any of you know how i could do this?

PS: My minimum api is 9, so i could use the onTaskRemoved() for API > 14, but what about the others?

Steven Smith
  • 111
  • 1
  • 2
  • 11
  • By swiping, you mean by dismissing from recents? – Yurii Tsap Oct 11 '16 at 11:58
  • I would really appreciate an answer too. Been having this problem for some years now. – cherry-wave Oct 11 '16 at 11:58
  • Possible duplicate of [How to handle code when app is killed by swiping in android?](http://stackoverflow.com/questions/19568315/how-to-handle-code-when-app-is-killed-by-swiping-in-android) – weston Oct 11 '16 at 12:10
  • @weston , that is a kind of similar question, but my solution should be a bit different. I just want to react when someone swipes the app, in order to send a message to the server to close my socket. But i think that it would be a bad practice to keep the service running, what would be the problems caused by that (the service running on background, with the socket closed ? – Steven Smith Oct 11 '16 at 13:12
  • You can do whatever you want to do in `onTaskRemoved` – weston Oct 11 '16 at 13:13
  • I think onTaskRemoved would work, but my minimum api is 9 and that method was only inserted on API 14. – Steven Smith Oct 11 '16 at 13:32
  • 1
    @cherry-wave check if this works for you mate. If you find any other solution, please tell me. I can't use the onTaskRemoved since my minimum API is 9, but hopefully it works for you . – Steven Smith Oct 11 '16 at 17:00

0 Answers0