這裏我有一個函數checkupdate(),其中我的應用程序檢查更新可用於用戶,所以我需要顯示兩個進度對話框,當服務器在請求時(檢查進程)和其他同步進程正在進行,並且這兩個進程是在應用程序的負載上完成。 現在的問題是我無法顯示這兩個進度對話框,這裏只有第一個線程檢查更新正在運行並且應用程序被終止。 等待您的寶貴答案。如何在一個函數中使用兩個線程?
public void CheckUpdate()
{
//----------------Process of checking the updates--------------------------
try
{
progressDialog = ProgressDialog.show(this, "Wait", "Checking update...", false, true);
Thread thr1 = new Thread()
{
public void run()
{
int Flag = call.CheckUserUpdate(UsrId);
Update = Flag;
progressDialog.dismiss();
//stop();
interrupt();
}
};
thr1.start();
}
catch(final Exception e)
{
}
//---------------Process of Synchronization----------------------------------------------
try
{
progressDialog1 = ProgressDialog.show(this, "Wait", "Synchronizing...", false, true);
Thread thr2 = new Thread()
{
public void run()
{
if(Update == 1)
{
SyncData();
final int UpdateFlag = 1;
call.UpdateUserUpdate(UsrId, UpdateFlag);
progressDialog1.dismiss();
}
else
{
progressDialog1.dismiss();
}
progressDialog1.dismiss();
}
};
thr2.start();
}
catch(final Exception e)
{
}
}