How to raise a toast in AsyncTask, I am prompted to used the Looper

前端 未结 6 1910
春和景丽
春和景丽 2020-11-29 08:20

I have tasks completed by AsyncTask in background. At some point I need to issue a Toast that something is completed.

I\'ve tried and I failed because Caused

6条回答
  •  一向
    一向 (楼主)
    2020-11-29 08:35

    If you want to display the Toast from the background thread you'll have to call runOnUiThread from doInBackground. I don't believe there's another way.

    Edit: I take that back. I think you can implement onProgressUpdate, which runs on the UI thread, to show the Toast and make calls to publishProgress from doInBackground.

提交回复
热议问题