Search code examples
androidprogress-barspinnersplash-screen

How to add a spinner to a splashscreen in android


I have implemented a Splash Screen on an android app I am building using Android Studio and I would like to add a spinner to the splash screen. Can anyone give me a hand on this:

Here is the code on my splashScreen.java Class:

package com.packagename.appname;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

/**
 * Created by VAIO1 on 05/09/2014.
 */
public class splashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);
        Thread logoTimer = new Thread() {

            public void run() {
                    try {
                           sleep(3000);
                           Intent splashIntent = new Intent("com.packagename.appname.SPLASH");
                           startActivity(splashIntent);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } finally {
                            finish();
                    }
               }

        };
        logoTimer.start();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

}

Here is the code for my splash.xml:

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/splashId">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:src="@drawable/screen"
        android:cropToPadding="false"
        android:scaleType="fitXY"/>


</LinearLayout>

Thank you for any feedback on how to achieve this.


Solution

  • use this code :-
    
    
    public class splashScreen extends Activity {
    
    ProgressDialog progressDialog;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            this.requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.splash);
            Thread logoTimer = new Thread() {
    
                public void run() {
                        try {
                               sleep(3000);
    
                                progressDialog = new ProgressDialog(Sync_Screen_activity.this);
                                progressDialog.setMessage("Wait..");
    
                                progressDialog.setCancelable(false);
                                progressDialog.show();
    
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } finally {
                               Intent splashIntent = new Intent("com.packagename.appname.SPLASH");
                               startActivity(splashIntent);
                                finish();
                        }
                   }
    
            };
            logoTimer.start();
        }
    
        @Override
        protected void onPause() {
            super.onPause();
        }
    
    }