Kenny Dabiri
Kenny Dabiri

Reputation: 353

Adding a progress indicator to Google's new Splashscreen pattern

Having gone through this blog post Splash Screens the Right Way , i discovered Google's new approach to creating splashscreens.

But my problem with this new method is adding a progress bar/indicator to the splashscreen.

I found several solutions but they are all custom xml layouts instead of Drawables

I also tried creating a progress dialog in my Background_splash.xml which is inside my drawable folder but i got an error that it is not allowed.

My app starts from the splash-screen to App intro activity then to the Main activity.

Is there any way to add a progress indicator/bar to this type of splashscreen?

Below are my codes created using the Splash Screens the Right Way Tutorial

Background_splash.xml

<?xml version="1.0" encoding="utf-8"?>

<item
    android:drawable="@color/grey"/>

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher"/>

</item>

AndroidManifest.xml

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

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

Styles.xml

 <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Upvotes: 0

Views: 1362

Answers (3)

Kenny Dabiri
Kenny Dabiri

Reputation: 353

As @lionscribe rightly said, there is no way to creating custom splash-screen with this approach. However, This http://saulmm.github.io/avoding-android-cold-startsmight help those who will like to animate elements in the new splash-screen approach.

Upvotes: 0

lionscribe
lionscribe

Reputation: 3513

The answer is you cannot! If you want to show the splash screen before the app loads, via the theme, it will have to be a static image.
If you want to show a progress bar AFTER the app loads, for example if you need to download data, then you can add a progress bar to splash activity, which will be shown AFTER the static image and app finished loading.
If you do not need to wait after app loads, then you are just wasting user time by adding another wait period, and making for a lousy app.
All of this can be understood from the comments and replies from the article you linked.

Upvotes: 1

7geeky
7geeky

Reputation: 438

Have you considered using AsyncTask to load the progressDialog. You might be trying to download something in the main thread which blocks splash screen to load.

public class MyActivity extends Activity {
private ProgressDialog pd = null;
private Object data = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Show the ProgressDialog on this thread
        this.pd = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false);

        // Start a new thread that will download all the data
        new DownloadTask().execute("Any parameters my download task needs here");
}

    private class DownloadTask extends AsyncTask<String, Void, Object> {
         protected Object doInBackground(String... args) {
         Log.i("MyApp", "Background thread starting");

         // This is where you would do all the work of downloading your data

         return "replace this with your data object";
     }

     protected void onPostExecute(Object result) {
         // Pass the result data back to the main activity
         MyActivity.this.data = result;

         if (MyActivity.this.pd != null) {
             MyActivity.this.pd.dismiss();
         }
     }
}    

}

Take this as a start point and put this as the inner class of your mainActivity.

Upvotes: 0

Related Questions