public class SplashScreen extends AppCompatActivity {
ProgressBarHandler progressBarHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
progressBarHandler = new ProgressBarHandler(this);
startTheDownload();
}
public void startTheDownload() {
progressBarHandler.show();
SaveDataOffline saveDataOffline = new SaveDataOffline(getApplicationContext());
saveDataOffline.execute();
AsyncTaskStopWords asyncTaskStopWords = new AsyncTaskStopWords(getBaseContext());
asyncTaskStopWords.execute();
if (saveDataOffline.getStatus() == AsyncTask.Status.FINISHED && asyncTaskStopWords.getStatus() == AsyncTask.Status.FINISHED) {
progressBarHandler.hide();
finish();
Log.i("qwer", "finished");
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
this.startActivity(intent);
}
}
}
我尝试了以下代码,但是它没有按照进度条进行操作
答案 0 :(得分:2)
使用get()
SaveDataOffline saveDataOffline = new SaveDataOffline(getApplicationContext());
saveDataOffline.execute().get();
AsyncTaskStopWords asyncTaskStopWords = new AsyncTaskStopWords(getBaseContext());
asyncTaskStopWords.execute().get();
代码将等到AsyncTask
完成后再转到下一行。