Splash screen while loading resources in android app

老子叫甜甜 提交于 2019-12-02 17:41:39
Sebastian Juarez

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.

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.

Blundell

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).

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!