Android传输不起作用



我有一个延迟很短的启动屏幕,延迟后它会移动到防溅屏上,但我似乎无法覆盖转换,我不明白为什么。。。尽管转换确实在调试模式下工作,这是非常奇怪的

package com.example.android.bubblestrouble;

导入android.app.Activity;导入android.content.Intent;导入android.os.Bundle;

公共类团队扩展活动{

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    final int delay = 3000;
    setContentView(R.layout.team);
    Thread welcomeThread = new Thread()
    {
    int wait = 0;
    @Override
    public void run() 
    {
        try {
                super.run();
                /**
                * use while to get the splash time. Use sleep() to increase
                * the wait variable for every 100L.
                */
                while (wait < delay) 
                {
                    sleep(100);
                    wait += 100;
                }
            } 
        catch (Exception e) 
        {
            System.out.println("EXc=" + e);
        } 
        finally 
        {
            /**
            * Called after splash times up. Do some action after splash
            * times up. Here we moved to another main activity class
            */
            startActivity(new Intent(Team.this, SplashScreen.class));
            Team.this.finish();
            Team.this.overridePendingTransition(R.anim.fade, R.anim.hold);
        }
    }
    };
    welcomeThread.start();
}

}

直接解决方案。在活动开始时立即显示您的启动图像,并通过计时器替换为所需的布局。类似这样的事情(Team活动的onCreate事件):

ImageView splashImage = new ImageView(this);
splashImage.setImageBitmap(splashBitmap); // or drawable/resource - as you like
setContentView(splashImage);
Thread timerThread = new Thread() {
    @Override
    public void run() {
        sleep(3000);
        Team.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                setContentView(R.layout.team);
            }
        });
    }
}
timerThread.start();

最新更新