Reputation: 19778
I have a splash screen activity SpalshScreenActivity.java
that shows for few seconds.
Meanwhile, it starts another Activity HomeActivity.java
, which does some processing and needs few seconds to load.
//Start a new activity in the BG
Intent i = new Intent(this, HomeActivity.class);
//i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(i);
//Remove this activity after few seconds so the HomeActivity shows in the FG
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
finish();
}
}, 2000);
How can I start the HomeActivity without bringing it to the front?
Upvotes: 3
Views: 2545
Reputation: 965
Only one activity can be running at any one time. It was because of this limitation that fragments were introduced to support two 'views' on a tablet. You generally don't want an entire activity if all its doing is showing a progress bar/spinner.
If all that the splash screen is doing is showing a spinner then you should really make it part of the layout in the MainActivity. Make the MainActivity layout a RelativeLayout and then spinner match parent with a background.
When the MainActivity is done loading you can set visibility to gone. If you want you can even add an animation so that the splash screen flows of the screen.
Upvotes: 1
Reputation: 11
Start SpalshScreenActivity.java
on onCreate of HomeActivity.java
before setContentView
bug don't finish one. At this time HomeActivity.java
loads data and doesn't visible. After few seconds only finish splash
Upvotes: 0
Reputation: 13937
You can write the logic of the given activity in a fragment and swap the splash screen fragment with the loaded fragment when its done loading.
All this happens in the same activity
Upvotes: 0