このウェブサイトに基づいてダイアログを作成しますhttp://www.mkyong.com/android/android-progress-bar-example/
プログレスバーが100%になると、ダイアログは閉じますが、トーストは引き続き表示されます。バーが100%になった後も、progressHandlerがループを実行していることに気付きました。
どうすればこの問題を解決できますか?欲しいもの:プログレスバーが100%になると、ダイアログが閉じ、トーストが表示されて閉じます。
Thread background = new Thread(new Runnable() {
@SuppressWarnings("null")
public void run() {
try {
while (dialog.getProgress() <= dialog.getMax()) {
// wait 500ms between each update
Thread.sleep(100);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
} catch (java.lang.InterruptedException e) {
// if something fails do something smart
Toast.makeText(getApplicationContext(), "Error Occurs",Toast.LENGTH_LONG).show();
}
}
});
// start the background thread
background.start();
}
// handler for the background updating
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
dialog.incrementProgressBy(increment);
if(dialog.getProgress()==100){
editor.putInt("lastestSummaryNoSent",summary.getCurrentSummaryNo());
editor.commit();
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Update Finished", Toast.LENGTH_LONG).show();
}
}
};