Вы можете создать службу, которая прослушивает приложение, уничтожающее
class MyService: Service() {
override onBind(intent:Intent):IBinder {
return null
}
override onStartCommand(intent:Intent, flags:Int, startId:Int):Int {
return START_NOT_STICKY
}
override onDestroy() {
super.onDestroy()
}
override onTaskRemoved(rootIntent:Intent) {
// this will be called when Your when the application is destroyed or killed
// launch your Network request here
}
}
, и определить эту службу в файле манифеста:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
...>
...
<application
android:name=".MyApplication">
...
<service android:name=".MyService" android:stopWithTask="false"/>
</application>
</manifest>
, а затем запустить ее в своем приложении
class MyApplication: Application{
override onCreate(){
super.onCreate()
val intent = Intent(this, MyService::java.class)
startService(intent)
}
}
проверить это поток .