18
votes

I have a simple application, it starts, loads xml feed from the net, you can browse a list of news and then read details for a chosen news item. What I would like to do is have a splash screen, meaning as soon as you click application, it should display an image (app name in my case) and then display news list only after they've loaded.

I read about similar (I think) problems, and usually people say to use FrameLayout, but I can't really sort it out. I'm not sure if this can be done in the first activity that is launched, maybe I should just display this splash image in one activity and only then call activity displaying my news list?

I know that on iPhone you can set splash screen in app settings while developing, would be nice to have this functionality in android's app's manifest...

2
You know that a splash screen don't help with anything but make your app start even slower... please don't use them.Johan
I believe its disadvantages heavily outweigh any benefits you would gain from a splash screen.Anthony Forloney
I don't see any disadvantages, instead of looking at a black screen for 2 or 3 seconds (or longer), you're looking at an image, much nicer in my opinion, at least you know that the app started.pambuk
Another option would be to make the app background translucent that way desktop would show until news feeds loadFred Grott

2 Answers

35
votes

Android suggests you take advantage of using a splash screen when performing lengthy calculations on start up. Here's an excerpt from the Android Developer Website - Designing for Responsiveness:

"If your application has a time-consuming initial setup phase, consider showing a splash screen or rendering the main view as quickly as possible and filling in the information asynchronously. In either case, you should indicate somehow that progress is being made, lest the user perceive that the application is frozen." -- Android Developer Site

You can create an activity that shows a Progress Dialog while using an AsyncTask to download the xml feed from the net, parse it, store it to a db (if needed) and then start the Activity that displays the News Feeds. Close the splash Activity by calling finish()

Here's a skeleton code:


public class SplashScreen extends Activity{
   @Override
   public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      // set the content view for your splash screen you defined in an xml file
      setContentView(R.layout.splashscreen);

      // perform other stuff you need to do

      // execute your xml news feed loader
      new AsyncLoadXMLFeed().execute();

   }

   private class AsyncLoadXMLFeed extends AsyncTask<Void, Void, Void>{
      @Override
      protected void onPreExecute(){
            // show your progress dialog

      }

      @Override
      protected Void doInBackground(Void... voids){
            // load your xml feed asynchronously
      }

      @Override
      protected void onPostExecute(Void params){
            // dismiss your dialog
            // launch your News activity
            Intent intent = new Intent(SplashScreen.this, News.class);
            startActivity(intent);

            // close this activity
            finish();
      }

   }
}

hope that helps!

2
votes

I know this is old but for those of you who are still facing this problem, you can use this simple android-splash library to show your splash screen.

SplashBuilder
        .with(this, savedInstanceState)
        .show();

You can set SplashTask that will execute while the splash screen is displayed.