What are alternative approaches to Download file other than AsyncTask - need to replace asynctask as it is deprecated.
Thanks in advance.
What are alternative approaches to Download file other than AsyncTask - need to replace asynctask as it is deprecated.
Thanks in advance.
WorkManager is used for background tasks. You should create a Worker class e.g. FileDownloadWorker. If you need to do the file download asynchronously, you can extend your Worker class from ListenableWorker.
To download files Android has released latest api https://developer.android.com/reference/android/app/DownloadManager
Use Kotlin Coroutines to handle asynchronous operations. Example:
suspend fun download(): InputStream = withContext(Dispatchers.IO) {
// a download function that returns a byte stream
}