【发布时间】:2020-11-21 15:01:33
【问题描述】:
已经有很多关于这个主题的答案,但我无法让我的工作。
从其中一项活动中,我这样调用我的 asynctask:
DownloadChapters().execute(currentChapUrl)
我的异步任务如下所示:
class DownloadChapters() : AsyncTask<String, Void, String>() {
override fun doInBackground(vararg startingChapUrl : String): String? {
//processing.. downloading from url's etc..
val result = "A total of $chapCount chapters Downloaded"
return result //I want to show this "result" as a toast message.
}
//trying to showing toast message here, but I cant get the context right, is what I am guessing. Please help.
override fun onPostExecute(result: String) {
super.onPostExecute(result)
Toast.makeText(this, result , Toast.LENGTH_SHORT).show()
}
}
错误显示在 toast 函数中。
None of the following functions can be called with the arguments supplied:
public open fun makeText(p0: Context!, p1: CharSequence!, p2: Int): Toast! defined in android.widget.Toast
public open fun makeText(p0: Context!, p1: Int, p2: Int): Toast! defined in android.widget.Toast
【问题讨论】:
-
有什么问题?这个话题是什么?问题是什么?
-
你需要传递一个
Context作为makeText函数的第一个参数。你正在传递this,这是你的AsyncTask。顺便说一句,AsyncTask已弃用。
标签: android kotlin android-asynctask android-context