Application or activity takes time to load some times
<p>I have created a startup activity from where I am calling another activity which has a view pager and shows some introductory pages. </p>

<p>This app was taking time to load so I thought to display a progress dialog till the activity loads, but that progress dialog also appears few seconds later. </p>

<p>startup activity:</p>

<pre><code>public class StartUpActivity extends AppCompatActivity {
    boolean isUserFirstTime, login;
    public static String PREF_USER_FIRST_TIME;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        isUserFirstTime = Boolean.valueOf(Utils.readSharedSetting(StartUpActivity.this, PREF_USER_FIRST_TIME, "true"));
        Intent introIntent = new Intent(StartUpActivity.this, SlidingActivity.class);
        introIntent.putExtra(PREF_USER_FIRST_TIME, isUserFirstTime);

        ProgressDialog dialog = new ProgressDialog(StartUpActivity.this);
        dialog.setMessage("Welcome to Mea Vita, please wait till the app loads.");
        dialog.setCancelable(false);
        dialog.setInverseBackgroundForced(false);
        dialog.show();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //Here you can send the extras.

                startActivity(new Intent(StartUpActivity.this,SlidingActivity.class));

                // close this activity
                finish();
            }
        }, 4000);
    }
}
</code></pre>

<p>This doesn't happen every time,only sometimes. What can be the possible reason for this? how can I stop this?
Any solution? Thank you..</p>