I have to run a function in the background and while the function is performing I have to show a progress dialog. this is how I call the function
.setPositiveButton(getString(R.string.str_accept)) { _, _ ->
CoroutineScope(Dispatchers.Default).launch {
pdfReportRequest()
}
and this is how I perform Coroutine task
private suspend fun pdfReportRequest() {
val alertDialog: AlertDialog?
progressDialogBuilder.setView(progressBinding.root)
.setTitle(context?.getString(R.string.exporting_as_pdf_file))
.show()
withContext(Dispatchers.Default) {
getResultFromApi()
}
alertDialog = progressDialogBuilder.create()
alertDialog.dismiss()
}
but it gives me this error
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()