How to start work in the background and show it later?

I have two activities: SplashActivity , and the other is MainActivity , an action that contains a web view.

I need to load webview when showing a splash screen. So I'm looking for a way to load MainActivity in the background in SplashActivity::onCreate() ;

If the intend is directly called, MainActivity is immediately brought to the forefront and also gets stuck in the webview.

I have searched for many splash screen solutions, for example, However, they do not initialize MainActivity until the burst time expires.

+7
source share
3 answers

Android applications can cache web data. You can take advantage of this. (and it worked for me). What I've done:

  • I created a webview in the splash screen.
  • did not bind it to the user interface,
  • requested a webpage that I need in my core business.
  • After loading WebView into your splash screen, start another activity.

WebView will use the WebView cache created in the splash screen.

+6
source

First you can run MainActivity and run SplashActivity in onCreate() MainActivity . After the required duration, you can simply close SplashActivity and MainActivity again so that it looks like you started Main from Splash.

Let me explain this -

In MainActiviy use intent and run SplashActivity using startActivity , not startActivityForResult , since you don't want to pass the result from SplashActivity to MainActivity .

Now that you are in SplashActivity , start the stream and wait in the stream for the desired duration, and then call finish() so that SplashActivity closes and the previously launched MainActivity appears in the foreground.

Hope this helps.

+12
source

I hope this should work fine ...

  ProgressDialog pd; pd = ProgressDialog.show(YOUR_ACTIVITY.this,"Loading...", true, false); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Intent intent = new Intent(YOUR_ACTIVITY.this, NEXT_ACTIVITY.class); startActivity(intent); pd.dismiss(); } }).start(); } }); 
-2
source

All Articles