title: Using a splash screen across activities
body: <p>I've a login screen as my first activities. It has an <code>AsyncTask</code> object for login verification using web services. It loads the main activity which has tabs as activities. The main activity then loads my first tab which also has an <code>AsyncTask</code> object to load some data. I want to show a splash screen from the start of login verification (<code>onPreExecute</code> of LoginActivity) till the FirstActivity loads its data (<code>onPostExecute</code> of FirstActivity). I've started implementing it but I was denied the desired result. The splash screen goes away after the <code>onPostExecute</code> of LoginActivity and the login screen reappears for a split second. After that my FirstActivity loads without a showing splash screen. </p>
  
  <p>How do I continue showing the splash screen across these activities? </p>
  
  <p>I'm aware that this sounds quite complex. But I've spent a lot of time to figure this out on my own and I haven't succeeded yet. Any kind of help is appreciated. Thank you! </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>LoginActivity:</p>
  
  <pre><code>    public Dialog mSplashDialog;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.login);
  
              et1 = (EditText) findViewById(R.id.ev_Login_ID);
      et2 = (EditText) findViewById(R.id.ev_Passward);
  
      // Activity Specicfic code
  
      }
  protected void showSplashScreen() {
      mSplashDialog = new Dialog(this, R.style.SplashScreen);
      mSplashDialog.setContentView(R.layout.splashscreen);
      mSplashDialog.setCancelable(false);
      mSplashDialog.show();
      }
  public class LoginProcess extends AsyncTask&lt;Object, Void, Void&gt; {
      private LoginActivity activity;
  
  
      private LoginProcess(LoginActivity activity) {
          this.activity = activity;
      }
  
  
      /**
       * Showing the dialog on the UI thread.
       */
      @Override
      protected void onPreExecute() {
          showSplashScreen();
      }
  
      /**
       * Performing the heavy lifting in the background thread thread.
       */
      @Override
      protected Void doInBackground(Object... params) {
          try {
  
  
          // User Validation  
  
  
      }
  
      /**
       * When the task is completed, notifiy the Activity.
       */
      @Override
      protected void onPostExecute(Void unused) {
  
                      Intent i = new Intent(LoginActivity.this, MainActivity.class);
                      i.putExtra("FromOtherTab", true);
                      startActivity(i);
                      finish();
                  }
  
  
  }
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Bundle extras = getIntent().getExtras();
  
      // create tabs and set current tab to FirstActivity
  
      }
  </code></pre>
  
  <p>FirstActivity:</p>
  
  <pre><code>public Dialog mSplashDialog;
  private FetchData mTask;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mydashboard);
  
    }
  
  protected void removeSplashScreen() {
      if (mSplashDialog != null) {
          mSplashDialog.dismiss();
          mSplashDialog = null;
      }
  
  private class FetchData extends AsyncTask&lt;Object, Void, Void&gt; {
  
  private FirstActivity activity;
  
  
  /**
   * Performing the heavy lifting in the background thread thread.
   */
  @Override
  protected Void doInBackground(Object... params) {
      // Load data
  
  }
  
  /**
   * When the task is completed, notifiy the Activity.
   */
  @Override
  protected void onPostExecute(Void unused) {
      // Here I want to call removeSplashScreen();
  
  }
  </code></pre>
  
  <p>Currently, the splash screen loads until the LoginActivity thread is running. After that, FirstActivity starts. A blank layout appears for a second (until the data from FirstActivity is loaded) and then the proper screen is displayed. I want to continually show the splash screen until the onPostExecute of FirstActivity. If I create a new mSplashDialog in FirstActivity then I get two separe instances of splashscreen. First disappears just before the new one appears. I'm not sure how to get the same mSplashDialog spinning when FirstActivity loads.</p>