开发者

Toast fails to show when within a AsyncTask

开发者 https://www.devze.com 2023-04-09 07:17 出处:网络
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

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 nev开发者_运维百科er shows. How do I take the Toast get shown after the data gets posted?

I think the issue is within the context.

http://pastie.org/2616524

UPDATE

I have updated the link, because i have since moved the upload logic into a different .java file.


Your sample look OK. If Activity, to which mContext variable belongs is currently active, it should show. Not in other case.

try this modification:

new UploadImage(ImageUploadActivity.this).execute(sentImage);

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 like class UploadImage extends AsyncTask<String, Void, String>

This means:

  • is type of params to doInBackground(String... arg)
  • is type of progress
  • is type of result from doInBackground to onPostExecute

So change your onPostExecute declaration to this:

protected void onPostExecute(String result)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号