如何在android中显示欢迎屏幕?

时间:2011-02-14 15:45:45

标签: android

您好,我想要一个屏幕,我的徽标应该显示2-3秒,然后它应该进入主程序。

我该如何实现?

3 个答案:

答案 0 :(得分:3)

这是一个简单的splashScreen实现:

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();

        }
    };

}

变量延迟表示在切换到另一个之前splashScreen活动的暂停时间。

答案 1 :(得分:1)

答案 2 :(得分:0)

这里我附加了初始化基于位置的应用程序的启动画面的完整代码。

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);
}

}