Reputation: 223
I am developing a game for android, it takes a few seconds of time to load everything before you can play. During this time or the splash screen, I would like to display a progress bar to show the user work is being done. Then kill the splash activity and launch my main activity. I have a splash screen made with a progress bar calling a async function that only is working with the sleep function as a place holder for the progress bar to show information. It then takes a few seconds after its completed to launch the main activity. The question is how do I load the activity and show the progress of it with the horizontal progress bar in the splash activity? I've tried to fully understand the activity life cycle. I understand the onCreate()
method creates the activity and then once it's finished then calls onStart()
automatically. But as stated before I want to just load the activity then start it manually.
Upvotes: 3
Views: 5422
Reputation: 2570
If you are setting the view via an xml file, this is relatively simple. The view is not inflated until you call setContentView(R.layout.YOUR_XML_FILE);
Postpone calling this, or call it on another xml file with a simple infinite loading widget, then call the setContentView()
on the real xml file when ready.
Upvotes: 1
Reputation: 9784
You can't preload the Activity
. Start the Activity
, display the splash screen / progress bar, and load the data on another thread besides the main thread. Once the data is finished loading, switch the view with a ViewFlipper
. I don't see a reason for multiple Activity
's.
Upvotes: 0
Reputation: 14226
You can not preload an Activity
itself.
Instead you should try to load the data needed by that Activity
within your splash screen.
When loaded, hand it over to your main Activity
.
You can load images from disk/flash into memory, prepare internal data structures, things like that.
However, you can not create the layout or initialize the real main Activity
.
Upvotes: 1