0

我有一个广播接收器。在那里我创建了一个新线程。如何在该线程中显示敬酒?

谢谢

4

3 回答 3

3

使用以下代码从非 UI 线程执行 UI 操作

new Handler(Looper.getMainLooper()).post(new Runnable() {

            @Override
            public void run() {
                // your stuff to update the UI

            }
        });
于 2013-04-23T05:33:46.240 回答
1

试试这个代码

public void start_insert() {
        pDialog.show();
        new Thread() {
            @Override
            public void run() {
                int what = 0;
                try {
                    // Do Something in Background
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    what = 1;
                    e.printStackTrace();
                }
                handler22.sendMessage(handler22.obtainMessage(what));
            }
        }.start();
    }

    private Handler handler22 = new Handler() {
        @Override
        public void handleMessage(Message msg) {
                pDialog.dismiss();

                Toast.makeText(getApplicationContext(), "SuccessFull",
                        10).show();

        }
    };
于 2013-04-23T05:40:30.060 回答
0
 Activity_Name.this.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // your stuff to update the UI

            }
        });

使用此代码更新 UI 线程或执行任何 UI 相关操作。

于 2013-04-23T05:30:33.187 回答