Where to create raster images, etc.

As my application (game) is getting bigger and bigger, I ran into a problem.

I have an action in the menu with the "start the game" button - when the user clicks this button, he starts the main game - now in this operation I create raster images, etc. in the constructor, but there is so much that now, when the action begins, there is a slight delay - about 2 seconds - before the game starts.

I'm obviously doing something wrong - please, someone can advise how to get around this, so the delay (which should obviously happen) is not noticed by the user.

+4
source share
3 answers

Download the ones you need right away. Download the rest to a background thread (possibly AsyncTask). If you need one before it can be downloaded, pause or set the download screen as needed.

+3
source

You can start downloading bitmaps in the background of your menu activity, or even when your application is created using a background thread or AsyncTask . You still need some kind of loading screen if the user moves to the main game before you finish downloading all the bitmap images.

+1
source

You can also run IntentService to load a bitmap. When the bitmap loads, the IntentService can send broadcasts using the LocalBroadcastManager. Then every component that cares about the result can register BroadcastReceiver with LocalBroadcastManager.

0
source

All Articles