14

I'd like to have a splash screen while loading resources (images and sounds). How do I know everything is loaded? Are all resources loaded at app startup?

Thanks

jul
  • 36,404
  • 64
  • 191
  • 318

4 Answers4

22

For accordingly implementing a splash screen in Android you want to:

  1. Show a foreground screen with some progress indication for the user.
  2. Execute a background thread for doing tasks that take some indefinitive time.
  3. Both threads communicating between them, as you need the foreground to show the progress on the background.
  4. Correctly kill the background thread when it finishes doing it's task. If you are planning to use AsyncTask in Android you have an issue there. (Link)

I've found this tutorial and I strongly suggest it:http://www.41post.com/4588/programming/android-coding-a-loading-screen-part-1

Part 1 accomplish this basic task, part 2 shows you how to correctly kill the AsyncTask. And part 3 puts a customized view in the foreground instead of the ProgressActivity.

Community
  • 1
  • 1
Sebastian Juarez
  • 3,317
  • 2
  • 21
  • 20
  • In step 2 instead of waiting some indefinitive time, can I know when everything is loaded and then dismiss the splash screen? – DrFred Mar 30 '15 at 15:30
5

Here you go, wrote a tutorial on how to create a SplashScreen with a progress bar:
http://blog.blundellapps.com/tut-splashscreen-with-progress-bar/

Basically, instead of your thread it starts an ASyncTask, you pass a reference to your progressSpinner into the ASyncTask and this will update it as the thread is downloading resources (or whatever you want to do).

enter image description here

Pang
  • 9,564
  • 146
  • 81
  • 122
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • Pretty good! I don't why the moderators sometime remove these kind of answers, which points to a solution which resides in an external source, like yours. At least, it happened to me :(... Any way, it (the blog) gives a very good example of implementing a progress bar. Thanks. – ivanleoncz Nov 29 '16 at 23:19
5

You could do all your loading in an asyncTask then your onPostExecute remove the splash screen. This would help ensure that you don't block the UI thread while doing any expensive tasks that could cause an ANR popup.

csaunders
  • 1,712
  • 1
  • 15
  • 20
2

Here is a complete tutorial on how to get it done. I've used this one myself with great results.

http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/

Kevin Parker
  • 16,975
  • 20
  • 76
  • 105
  • Instead of waiting an arbitrary amount of time, is there any way to know when everything is loaded to start the app? – jul Feb 17 '11 at 11:39
  • Then all you have to do is start from your Splash and launch your main activity. You then have a nice splash screen while your activity is loading. – MinceMan Feb 18 '12 at 16:50
  • Link seems dead - *"Page not found"*. – Pang Aug 01 '17 at 09:54