1

So in Java you'd call it like

new AsyncTask<Void, Void, Int>() { }.execute()

How would you do this in Kotlin as I can't seem to get it working? The compiler just tells me that I can't instantiate an abstract class when I attempt this in Kotlin

var a = AsyncTask<Void, Void, Int> {}.execute()

I'm still learning Android in general so some guidance here wouldn't go a miss, thanks.

//EDIT//

This appears to have worked but the compiler has concerns about memory leakage:

var a = object: AsyncTask<Void, Void, Int>() {
            override fun doInBackground(vararg p0: Void?): Int {
                TODO("Not yet implemented")
            }
        }.execute()
  • 2
    `AsyncTask` become deprecated. Why not use coroutines? https://stackoverflow.com/a/62748880/1731626 – Sergio Sep 02 '20 at 18:39
  • I just removed it altogether as it was outside the scope of my app. Doesn't need any background tasks. Thanks though, I'll keep this in mind – Mitchell Houston Sep 02 '20 at 21:49

0 Answers0