Reputation: 93
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);
}
}
}
I tried the following code but its not working it stuck with the progress bar
Upvotes: 0
Views: 92
Reputation: 353
Use get()
SaveDataOffline saveDataOffline = new SaveDataOffline(getApplicationContext());
saveDataOffline.execute().get();
AsyncTaskStopWords asyncTaskStopWords = new AsyncTaskStopWords(getBaseContext());
asyncTaskStopWords.execute().get();
Code will wait until AsyncTask
finishes before going to the next line.
Upvotes: 2