title: Android: How to show animated splash screen while loading resources
body: <p>I want to show an animated image (currently using set of PNGs) as splash screen while resources are getting loaded.</p>
  
  <p>I have been able to show the splash screen using <a href="http://www.codeproject.com/Articles/113831/An-Advanced-Splash-Screen-for-Android-App" rel="nofollow">this</a>. But the problem is: the splash screen shows for a specified time then there is a black screen for 2-3 seconds and then <code>index.html</code> gets loaded.</p>
  
  <p>Ideally what I want is to show the splash screen while resources get loaded. Once resources are loaded, pull the splash screen and immediately load the <code>index.html</code> file. </p>
  
  <p>Below is my code:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // Splash screen view
      setContentView(R.layout.splash);
  
      // Start animating the image
      final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
      splashImageView.setBackgroundResource(R.drawable.flag);
      final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
      splashImageView.post(new Runnable(){
          @Override
          public void run() {
              frameAnimation.start();             
          }           
      });
  
  
      final SplashScreen sPlashScreen = this;   
  
      // The thread to wait for splash screen events
      mSplashThread =  new Thread(){
          @Override
          public void run(){
              try {
                  synchronized(this){
                      // Wait given period of time or exit on touch
                      wait(10000);
                  }
              } 
              catch(InterruptedException ex){                 
              }
  
              finish();
  
              // Run next activity
              Intent intent = new Intent();
              intent.setClass(sPlashScreen, SomeActivity.class);
              startActivity(intent);
              //stop();               
          }
      };      
      mSplashThread.start();      
  } 
  
  public class SomeActivity extends DroidGap {                
      @Override
      public void onCreate(Bundle savedInstanceState) {    
       //some code to copy database files.
      }
  }
  </code></pre>
  
  <p>Please note my development environment. android-sdk: api level 17, Phonegap: 2.1.0.</p>