1
我目前是Android的新手。我看到很多情況下,加載屏幕能夠啓動文件的下載。我想知道在加載屏幕完成處理其後臺任務時,我如何才能在postexecute()命令上啓動畫廊。 以下是後臺任務中的代碼。我是否想在這個背景下編寫代碼,讓圖庫在postexecute()上執行,或者還有其他辦法可以做到這一點。加載屏幕後運行圖庫完成加載
P.S我的載入畫面和畫廊在不同的java文件。那麼有什麼辦法可以讓畫廊在postexecute命令的加載屏幕後立即運行?
感謝
//The code to be executed in a background thread.
@Override
protected String doInBackground(String... strings)
{
/* This is just a code that delays the thread execution 4 times,
* during 850 milliseconds and updates the current progress. This
* is where the code that is going to be executed on a background
* thread must be placed.
*/
try
{
//Get the current thread's token
synchronized (this)
{
//Initialize an integer (that will act as a counter) to zero
int counter = 0;
//While the counter is smaller than four
while(counter <= 4)
{
//Wait 850 milliseconds
this.wait(850);
//Increment the counter
counter++;
//Set the current progress.
//This value is going to be passed to the onProgressUpdate() method.
publishProgress(counter*25);
}
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
return null;
}
//Update the TextView and the progress at progress bar
@Override
protected void onProgressUpdate(Integer... values)
{
//Update the progress at the UI if progress value is smaller than 100
if(values[0] <= 100)
{
tv_progress.setText("Progress: " + Integer.toString(values[0]) + "%");
pb_progressBar.setProgress(values[0]);
}
}
我已經嘗試過這種方法,但它仍然給我一個黑屏。任何關於//啓動畫廊代碼的意見,以便我可以啓動它? – user1856686