I'm currently using below structure in my splash screen activities in order to show it for specified time period:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startMainActivity();
}
}, SPLASH_DISPLAY_LENGHT);
However I'm just creating an app which loads some information on its splash screen from network using an AsyncTask like this:
startUpAsyncTask = new StartUpAsyncTask(this);
startUpAsyncTask.execute();
Now I want to implement Handler such that:
- If something failed during network load, it stops handler to move to MainActivity.
- If network loading last longer than
SPLASH_DISPLAY_LENGHT
activity waits till network load completes inStartUpAsyncTask
and then move to next activity. - If network
StartUpAsyncTask
finished very soon, splash screen is shown for at leastSPLASH_DISPLAY_LENGHT
time length.
My problem is how to synchronize this AsyncTask and Handler to achieve such constraints.