Toast 在 AsyncTask 内时无法显示
我有一个简单的应用程序,它将图像(Base64 编码)发送到服务器,服务器可以很好地获取此数据,因为 PHP 脚本向我发送了一封附有 Base64 数据的电子邮件。然而,任务完成后,吐司永远不会显示。数据发布后如何显示Toast?
我认为这个问题是在上下文中的。
更新
我已经更新了链接,因为我此后已将上传逻辑移至不同的 .java 文件中。
I have a simple application which sends an image (Base64 encoded) to a server, the server gets this data fine because the PHP script sends me an email with the Base64 Data attached. However, after the task gets completed the toast never shows. How do I take the Toast get shown after the data gets posted?
I think the issue is within the context.
UPDATE
I have updated the link, because i have since moved the upload logic into a different .java file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的样品看起来不错。如果 mContext 变量所属的 Activity 当前处于活动状态,则应该显示。其他情况则不然。
尝试此修改:
http://developer.android.com/guide/主题/ui/notifiers/toasts.html
Android toast.makeText上下文错误
编辑:AsyncTask的类型声明错误
您的
AsyncTask
声明看起来像class UploadImage extends AsyncTask
这意味着:
doInBackground(String... arg)< 的参数类型/code>
doInBackground
到onPostExecute
的结果类型,因此将您的
onPostExecute
声明更改为此:或更改的返回类型将
doInBackground
更改为
并将类声明更改为:class UploadImage extends AsyncTask
http://developer.android.com/reference/android/os/AsyncTask.html
Your sample look OK. If Activity, to which mContext variable belongs is currently active, it should show. Not in other case.
try this modification:
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
Android toast.makeText context error
EDIT: WRONG TYPE DECLARATION OF AsyncTask
your
AsyncTask
declaration looks likeclass UploadImage extends AsyncTask<String, Void, String>
This means:
doInBackground(String... arg)
doInBackground
toonPostExecute
So change your
onPostExecute
declaration to this:or change return type of
doInBackground
to<Bitmap>
and change class declaration to:class UploadImage extends AsyncTask<String, Void, Bitmap>
http://developer.android.com/reference/android/os/AsyncTask.html