0

私はBroadcastReceiverを持っています。そこで新しいスレッドを作成します。そのスレッドでトーストを表示するにはどうすればよいですか?

ありがとう

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 に答える