Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

splash screen with a loading animation (Android Apps)

I am developing my first android app with eclipse adt. I succeeded with making a splash screen but i want to show a loading animation. I have the following code :

package com.sunil.splash;

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

public class Splash extends Activity {
private long ms=0;
private long splashTime=2000;
private boolean splashActive = true;
private boolean paused=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Hides the titlebar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.splash);

    Thread mythread = new Thread() {
        public void run() {
            try {
                while (splashActive && ms < splashTime) {
                    if(!paused)
                        ms=ms+100;
                    sleep(100);
                }
            } catch(Exception e) {}
            finally {
                Intent intent = new Intent(Splash.this, Home.class);
                startActivity(intent);
            }
        }
    };
    mythread.start();
}
}

Could you help me with this?

like image 603
aymen khalifi Avatar asked Feb 21 '26 07:02

aymen khalifi


1 Answers

Android has a default indeterminate progress widget. Just add it to your Loader layout (splash.xml):

<ProgressBar
    android:id="@+id/my_progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    .....
/>
like image 92
Christophe Longeanie Avatar answered Feb 23 '26 17:02

Christophe Longeanie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!