Prachur
Prachur

Reputation: 1110

How to display a welcome screen in android?

Hi I want a screen which should appear for 2-3 seconds with my logo and then it should proceed to the main program.

How can I implement this?

Upvotes: 3

Views: 12491

Answers (3)

icaneatclouds
icaneatclouds

Reputation: 1170

Here is a simple splashScreen implementation:

public class SplashScreen extends Activity {


    private Handler mHandler;

    private long delay = 1000;
    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash_screen);

        Timer timer = new Timer();
        timer.schedule(task, delay);
    }


    TimerTask task = new TimerTask() {
        @Override
        public void run() {

        Intent in = new Intent().setClass(SplashScreen.this,
                        LoginActivity.class).addFlags(
                        Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(in);
        finish();

        }
    };

}

The variable delay indicates the pause time of your splashScreen Activity before switching into another.

Upvotes: 3

eyal
eyal

Reputation: 2409

here i attached a full code for splash screen that initalize location based application.

public class splashScreen extends Activity {

private LocationManager locationManager = null;
private LocationListener locationListener = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    setContentView(R.layout.splash);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    // Start the Animation of SplashScreen
    new Handler().postDelayed(new Runnable() {
        public void run() {
            ImageView imageView = (ImageView) findViewById(R.id.splashImageView);
            AnimationDrawable animation = (AnimationDrawable) imageView.getDrawable();
            animation.start();
        }
    }, 500);
    // Obtain user's location
    new Handler().post(new Runnable() {         
        public void run() {
            locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            String locationProvider = LocationManager.GPS_PROVIDER;
            locationManager.requestLocationUpdates(locationProvider, 1000, 0, locationListener);
            try { wait(5000); } catch (Exception e) {}
            if(locationManager != null) {
                locationManager.removeUpdates(locationListener);
            }
        }
    });
    // Start the Tabs screen.
    new Handler().postDelayed(new Runnable() {
        public void run() {
            Bundle extras = new Bundle();
            extras.putDouble(Constants.LATITUDE, ((MyLocationListener)locationListener).getLat());
            extras.putDouble(Constants.LONGITUDE, ((MyLocationListener)locationListener).getLng());
            Intent intent = new Intent(splashScreen.this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtras(extras);
            startActivity(intent);
        }
    }, 5000);
}

}

Upvotes: 0

ice911
ice911

Reputation: 1180

Check this out: Needed to make a Loading Screen in Android

Upvotes: 1

Related Questions