Start two activities simultaneously one in foreground other in background

Home / Uncategorized / Start two activities simultaneously one in foreground other in background

Question:
I have two activities SplashScreen and MainActivity.

MainActvity download some data and show it.

Now I want to start both activities on application start, MainActivity in background and SplashScreen in foreground and when the data of MainActivity download complete I want to make MainActivity foreground and finish SplashScreen.

I have seen many solution but no one is going good in my situation. Please give me some suggestion or example .


Answer:
I think it’s better to make splash screen to download data and when it completed show new activity (MainActivity). In onStart metod use downloaded data stored on phone.

Your example: The only way You can have resolve this your way is by start MainActivity first and from onStart start SplashScreen:
class SplashScreen extends Activitiy {

public void onStart() {
EventBus.register(this);
}

@Subscribe
public void finishedDownload(FinishedDownloadEvent) {
this.finish()
}
}

class MainActivity extens Activity () {

public void onStart () {
open(new Intent(SplashScreen.class)); // We would like to have

download();
}

public void download (OnFinish onFinish) {
… download

EventBus.post(new FinishedDownloadEvent());
}
}

I forgot:
class EventBus {

private final static Bus instance = new Bus();

public static void register (Object obj) {
instance.register(obj)
}

public static void post (Event obj) {
instance.post(obj)
}

}

EventBuss
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *