我正在使用消息和處理程序來更改執行線程時顯示的processdialog的消息。代碼如下。問題與消息處理程序
final ProgressDialog processdialog = ProgressDialog
.show(MultiBootManager.this, EMPTY,
EMPTY, true);
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.arg1) {
case 0:
System.out.println("msg0");
processdialog
.setMessage(getString(R.string.formating)
+ folderpath
+ getString(R.string.cachext3));
case 1:
System.out.println("msg1");
processdialog
.setMessage(getString(R.string.formating)
+ folderpath
+ getString(R.string.dataext3));
case 2:
System.out.println("msg2");
processdialog
.setMessage(getString(R.string.formating)
+ folderpath
+ getString(R.string.systemext3));
case 3:
System.out.println("endmsg");
processdialog.dismiss();
}
}
};
Thread checkUpdate = new Thread() {
@Override
public void run() {
String[] shellinput = { EMPTY,
EMPTY, EMPTY, EMPTY, EMPTY };
shellinput[0] = CMD_MKE2FS_EXT3;
shellinput[1] = folderpath;
if (cacheCheckBool) {
final Message m0 = new Message();
m0.arg1 = 0;
handler.sendMessage(m0);
shellinput[2] = CACHE_IMG;
processManager
.inputStreamReader(
shellinput, 20);
}
if (dataCheckBool) {
final Message m1 = new Message();
m1.arg1 = 1;
handler.sendMessage(m1);
shellinput[2] = DATA_IMG;
processManager
.inputStreamReader(
shellinput, 20);
}
final Message endmessage;
if (systemCheckBool) {
final Message m2 = new Message();
m2.arg1 = 2;
handler.sendMessage(m2);
shellinput[2] = DATA_IMG;
processManager
.inputStreamReader(
shellinput, 20);
}
endmessage = new Message();
endmessage.arg1 = 3;
handler.sendMessage(endmessage);
}
};
checkUpdate.start();
}
我遇到現在是該endmessage
在操作完成之前發送的問題,ProcessDialog
關閉在如0.5秒。如果所有Boolean
都爲真,則在System.out
中快速顯示msg1, msg2, msg3, emdmsg
並關閉。爲什麼會這樣?我如何解決它?