3

According to the documentation, we should call close method after we are done with http client instance. What is the right way to handle the close method of ktor http client in multiplatform env. ? In my case, I have a KMM project with android and ios. I am using HttpClient in common source set.

Or maybe the close method should be handled by specific applications instead of the multiplatform lib?

Barracuda
  • 477
  • 5
  • 19
  • What do you mean by "handle"? You can simply call `client.close()` on demand. – Phil Dukhov Feb 14 '22 at 12:35
  • The `close` method is available in the common source set. – Aleksei Tirman Feb 14 '22 at 13:15
  • @PhilipDukhov , I mean how do I get notified from an Android/IOs application that the application is closing? If I want to reuse http client while the application is active and close it when the application closes, how can I do this in common source set? – Barracuda Feb 14 '22 at 13:34
  • 1
    For Android, you can define an `onDestroy` https://developer.android.com/reference/android/app/Activity#onDestroy() method on the `MainActivity` that is called before an activity is destroyed. Btw, why do you need to close a client if resources will be freed anyway? – Aleksei Tirman Feb 14 '22 at 14:03

0 Answers0