F
F
foonfyrick2020-10-20 11:41:03
Android
foonfyrick, 2020-10-20 11:41:03

AsyncTask How to update the view if the task class is not nested?

How can I pass the view to the pre / postExecute methods, in which I want to display the results before and after the start of the thread execution? Or does the class inherited by AsyncTask have to be nested in Activity?

class MyTask():AsyncTask<Void,Void,Void>() {
    override fun doInBackground(vararg params: Void?): Void {
        TODO("Not yet implemented")
    }

    override fun onProgressUpdate(vararg values: Void?) {
        super.onProgressUpdate(*values)
    }

    override fun equals(other: Any?): Boolean {
        return super.equals(other)
    }

    override fun onPostExecute(result: Void?) {
        super.onPostExecute(result)
    }

    override fun onCancelled(result: Void?) {
        super.onCancelled(result)
    }

    override fun onCancelled() {
        super.onCancelled()
    }

    override fun onPreExecute() {
        super.onPreExecute()

    }

    override fun hashCode(): Int {
        return javaClass.hashCode()
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-10-20
@foonfyrick

If it's really necessary, then it is passed to the constructor WeakReference<ЧтоХочешьОбновлять>
. But it's better not to use AsyncTask at all. This is an ancient thing with a very bad api.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question