Android display Splash-Screen while loading

android splash screen while loading
beautiful splash screen android
full screen splash screen android
splash screen in android studio source code
android splash screen loading animation
android dynamic splash screen
splash screen transition android
splash screen in android using handler

I have an Android App, which shows a "Splash Screen" for 3 seconds. After that, the MainActivity gets loaded.

Unfortunately the MainActivity takes additional ~4 seconds to load. On first startup even longer. However when the App is loaded, everything runs smooth.

Now how can I achieve it, that the MainActivity gets loaded, during the display of the Splash Screen? It just should display an image until the whole thing loaded completely. I have read about Async-Task, but I'm not sure where to put it and how to use it properly. Can someone help me please?

SplashScreen.java

public class SplashScreen extends Activity {
    private static int SPLASH_TIME_OUT = 3000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_startup);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
}

MainActivity.java

public class MainActivity extends Activity implements OnClickListener, MediaController.MediaPlayerControl {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Some heavy processing
        //starting services
        //starting Google Text to Speech
        //and so on...

    }

}

If there are no specific constraints about the time the splash screen should be shown, you could use the AsyncTask in the following way:

public class SplashScreen extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_startup);
        startHeavyProcessing();

    }

    private void startHeavyProcessing(){
       new LongOperation().execute("");
    }

    private class LongOperation extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            //some heavy processing resulting in a Data String
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Thread.interrupted();
                }
            }
            return "whatever result you have";
        }

        @Override
        protected void onPostExecute(String result) {
            Intent i = new Intent(SplashScreen.this, MainActivity.class);
            i.putExtra("data", result);
            startActivity(i);
            finish();
        }

        @Override
        protected void onPreExecute() {}

        @Override
        protected void onProgressUpdate(Void... values) {}
    }
}

If the resulting data if of another nature than a String you could put a Parcelable Object as an extra to your activity. In onCreate you can retrieve the data with:

getIntent().getExtras.getString('data');

The (Complete) Android Splash Screen Guide, In the past, having splash screens in your Android app were not Not able to load heavy data/components while the splash screen is shown. Android display Splash-Screen while loading but getting black screen instead. This is using a theme with a background drawable then loading MainActivity from Splash.java which uses said theme to display an image while MainActivity processes and loads.

You should not be creating a new thread on startup, instead you should create a view that does not have to wait for your resources to load, as detailed in this article: Splash Screens the Right Way.

As stated in the article, you should create a layer-list drawable instead of a layout XML file:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Fill the background with a solid color -->
    <item android:drawable="@color/gray"/>

    <!-- Place your bitmap in the center -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

Then create a theme using the drawable file as a background. I use the background attribute instead of the windowBackground attribute as suggested in the article, because background takes the status and navigation bars into account, centering the drawable better. I also set windowAnimationStyle to null so that the splash screen does not animate the transition to the MainActivity:

<resources>

    <!-- Base application theme -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <!-- Splash Screen theme -->
    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:background">@drawable/background_splash</item>
        <item name="android:windowAnimationStyle">@null</item>
    </style>

</resources>

Then declare your theme in the manifest for your SplashActivity:

<activity android:name=".SplashActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

And finally all you have to do in your SplashActivity is start your MainActivity, and the splash screen will only show for as long as it takes for your app to configure:

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

Building the perfect splash screen, be quick. How quick? As quick as possible, but never more than 2 or 3 seconds. Any user who uses your app regularly will quickly get frustrated if they have to sit around and wait for an app to open for more than a few seconds. For accordingly implementing a splash screen in Android you want to: Show a foreground screen with some progress indication for the user. Execute a background thread for doing tasks that take some indefinitive time. Both threads communicating between them, as you need the foreground to show the progress on the background.

How about, in the interest of simplicity, you combine your splash activity with your main activity? That way you get the best of both worlds, namely a splash screen while your data is preparing the first time, and a quick startup when it's been prepared previously. Making the user wait for nothing is not really good form...

Something like:

public class MainActivity extends Activity implements OnClickListener, MediaController.MediaPlayerControl {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Initially shows splash screen, the main UI is not visible
        setContentView(R.layout.activity_main);  

        // Start an async task to prepare the data. When it finishes, in
        // onPostExecute() get it to call back dataReady()
        new PrepareDataAsyncTask(this).execute();

    }

    public void dataReady() {
        // Hide splash screen
        // Show real UI
    }

}

Creating a Splash Screen in Android : Part 1, Did you notice the white screen while loading the app ? Yeah, that's the issue, we call Cold Start which is kinda bad User Experience. This can go worse if you  I wrote an article on making a website appear in a WebView component for an Android application.In an effort to maintain simplicity, here’s a separate article teaching how to displaying a loading (“splash”) screen while the webpage loads.

your splash screen code works fine but when you call next activity then in onCreate() use Asynctask for your heavy tasks...

The right way to implement a Splash Screen in Android, Theme for Splash Screen: Do you know when an activity is called Android OS first see in the manifest is there any theme for that activity and load the theme from  My app displays a splash screen while the app is loading. I want to put an animated progress bar below the icon on the splash screen. I tried using XML, but it's crashing! Says invalid tag progressbar. Here's my code to call the splash screen, in styles.xml

I have had similar problem. There was a blank loading screen (not even toolbar). Mu culprit was in the manifest in the MainActivity:

 android:launchMode="singleInstance"

The best way to implement Splash Screens on Android, Actually I'm not quite ok with the recreate() call but lot's of developers do usually all UI initialization on the onCreate() callback and after the  Display a loading overlay on Android screen. Ask Question Asked 6 years, 8 months ago. Active 1 year, Splash screen while loading resources in android app.

Splash Screen in The Right Way (Android Studio Tutorial), Splash Screen is used to display users something useful other than a white screen that Duration: 9:36 Posted: Apr 27, 2019 Create a Splash Screen on Android : the Right Way ! Ideal to display your brand logo during cold start of applications. Get unlimited access to the best stories on Medium — and support

How to Create Welcome Screen (Splash Screen) in Android Studio , Source code https://github.com/SabithPkcMnr/SplashScreen Source code - direct Screen Duration: 4:02 Posted: Sep 6, 2016 Android splash screen are normally used to show user some kind of progress before the app loads completely. Some people uses splash screen just to show case their app / company logo for a couple of second. Unfortunately in android we don’t have any inbuilt mechanism to show splash screen compared to iOS.

How to Add a Splash Screen—The Right Way, After all, a splash screen should be shown while the app is loading and The way to show a splash screen is to use the android:windowBackground attribute of If you have to display text, you will need to rasterize it as well. I am new in Android App and this is my first App. I already create splash screen and works.. but after its gone theres a long white blank screen about 2-5 second then the url begin to load.. And my question is.. how to make some loading or progress bar in Splash Screen while loading URL? so no more white blank screen. Sorry for my bad english.

Comments
  • One workaround may be to use only MainActivity, initially displaying splash screen layout, later hiding/removing it (via the Handler.postDelayed(), for example) to show the actual Activity layout.
  • This new tip from the Android Developers might be helpful: plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd
  • Have you googled yet?There are tons of example for you.Check this androidhive.info/2013/07/…
  • Thanks for the comments! @Soham: My sample code is from exactly the same source like your link... So YES I have googled it. My problem however was solved here by TmKVU
  • This should be the accepted answer. It actually answers OP's question.
  • Good approach, but can we display a progress bar in the splash screen created this way?
  • @Journey No, the point is to show this screen before the resources are loaded. In order to show a progress bar, the resources would have to be loaded. An application shouldn't take that long to load its resources anyway, a matter of seconds. If your application handles a some other processes on startup, a good method to handle this would be to have a SplashActivity that starts a LoadingActivity which will handle those processes. If you use the same windowBackground, there will be no visual difference between the two, except now you can display a progress bar.
  • thanks a lot but dont forget to add parent="Theme.AppCompat.NoActionBar" to the SplashTheme style, it will not work without it
  • @HuseyinSahin The drawable used to create the bitmap should adhere to the intrinsic dp size of the drawable; so just use a smaller drawable, no? Layer drawables do have width and height attributes to override the intrinsic size, but according to Android Studio they are not supported until API level 23 (I'm not sure why this isn't reflected in the documentation).
  • So was launchMode="singleInstance" a good thing or a bad thing?