Posting Toast message from a Thread

前端 未结 4 2136
温柔的废话
温柔的废话 2020-12-03 22:09

My application launches a thread to query the web for some data. I want to display a Toast message when nothing is found, but my application always crashes.

I\'ve t

4条回答
  •  不思量自难忘°
    2020-12-03 22:30

    Try to post inside to a Handler object.

    final Handler mHandler = new Handler();
    final Runnable mUpdateResults = new Runnable() {
        public void run() {
            Toast(this, message, duration).show();
        }
    
    new Thread() {
        public void run() {
            mHandler.post(mUpdateResults);
        }
    }.start();
    

提交回复
热议问题