我有一个应用程序,其中我有 3-4 个线程,我希望第 2 个线程必须在第 1 个线程结束时启动,第 3 个在第 2 个线程结束时启动,依此类推.. 我正在给出代码..
//1st thread
new Thread(new Runnable() {
int progressStatus = 0;
public void run() {
progressStatus = dofirstWork();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress bar
handler.post(new Runnable() {
public void run() {
bar.setProgress(progressStatus);
}
});
}
private int dofirstWork() {
//do some work
return 25;
}
}).start();
//2nd thread
new Thread(new Runnable() {
int progressStatus = 0;
public void run() {
progressStatus = dosecondWork();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress bar
handler.post(new Runnable() {
public void run() {
bar.setProgress(progressStatus);
}
});
}
private int dosecondWork() {
//do some work
return 50;
}
}).start();
//3rd thread
new Thread(new Runnable() {
int progressStatus = 0;
public void run() {
progressStatus = dothirdWork();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Update the progress bar
handler.post(new Runnable() {
public void run() {
bar.setProgress(progressStatus);
}
});
}
private int dothirdWork() {
//do some work
return 75;
}
}).start();
实际上,我试图在第一次函数调用时以 25% 显示进度条,在第二次操作时以 50% 显示进度条等等.. on.. 请帮助