我目前是 Android 新手。我见过很多情况,加载屏幕能够启动文件的下载。我想知道当加载屏幕完成处理其后台任务时,我如何在 postexecute() 命令上启动图库。以下是后台任务中的代码。我是想在这个背景中编写代码以供画廊在 postexecute() 上执行,还是有其他方法可以做到这一点。
PS 我的加载屏幕和图库位于不同的 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]);
}
}