为什么我的第一个活动没有出现?

时间:2015-03-14 18:54:21

标签: java android android-studio

我制作了闪屏,但我的闪屏却没有显示出来。 4秒后,第二个闪屏将出现。 我想让我的闪屏显示4秒钟。 这是我的代码:

package com.geven.headsoccer.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class SplashScreen extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            startActivity(new Intent("com.geven.headsoccer.LIBGDX_GAME"));
        }



    }

3 个答案:

答案 0 :(得分:1)

如果你想让你的SplashScreen显示4秒钟,你为什么不使用Handler?

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

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {                
            startActivity(new Intent(SplashScreen.this, MainActivity.class));
            finish();
        }
    }, 4000);
}

答案 1 :(得分:0)

你必须使用一个处理程序。

new Handler().postDelayed(new Runnable() {

            // Using handler with postDelayed called runnable run method

            @Override
            public void run() {
                                startActivity(new Intent("com.geven.headsoccer.LIBGDX_GAME"));

                // close this activity
                finish();
            }
        }, 4*1000); // wait for 5 seconds

答案 2 :(得分:0)

new Handler().postDelayed(new Runnable()
    {
         /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */


        @Override
        public void run()
        {
            // This method will be executed once the timer is over
            // Start your app main activity
            //animation();
            Intent intent=new Intent(SplashScreen.this,com.geven.headsoccer.LIBGDX_GAME.class);
            startActivity(intent);
            //close this activity
            finish();
        }
    },4000); //SPLASH_TIME_OUT
}
  

检查你的意图

相关问题