Android: How to detect an application killed from the list of recent applications?

So, I saw the answers to this question in Stackoverflow, but I did not find the final answer. So, I ran into a problem: I split Thread into Socket. And I create and run this thread using the Application onCreate method. And I need to intercept this thread when the application was killed from the list of recent applications. If the user presses the back button, the system will call onDestroy, and in this situation I can intercept the socket thread. But I can not intercept the stream of sockets when a user kills an application from the list of recent applications.

Does anyone have a definitive answer how to solve this problem?

+5
source share
1 answer

you can either do this using the stopWithTask flag as true for the service in the manifest file.

Example:

<service android:enabled="true" android:name=".MyService" android:exported="false" android:stopWithTask="true" /> 
0
source

Source: https://habr.com/ru/post/1206314/


All Articles