私はBroadcastReceiverを持っています。そこで新しいスレッドを作成します。そのスレッドでトーストを表示するにはどうすればよいですか?
ありがとう
以下のコードを使用して、非 UI スレッドから UI 操作を実行します
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
// your stuff to update the UI
}
});
このコードを試してください
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();
}
};
Activity_Name.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// your stuff to update the UI
}
});
このコードを使用して、UI スレッドを更新するか、UI 関連の操作を実行します。