我正在使用消息和处理程序来更改在执行线程时显示的 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
都是真的,它会msg1, msg2, msg3, emdmsg
迅速显示System.out
并关闭。为什么会有这种行为?我如何解决它?