且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

启动/加载时的图像

更新时间:2023-12-05 16:37:22

创建一个新活动,显示图片几秒钟并重定向到您的主要活动:

Create a new activity that displays the image for a few seconds and redirects to your main activity:

public class SplashActivity extends Activity
{
    private static final long DELAY = 3000;
    private boolean scheduled = false;
    private Timer splashTimer;

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

        splashTimer = new Timer();
        splashTimer.schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                SplashActivity.this.finish();
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
            }
         }, DELAY);
       scheduled = true;
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if (scheduled)
            splashTimer.cancel();
        splashTimer.purge();
    }
}

将图片设置为此活动的背景。希望有所帮助。祝你好运!

Set your image as the background for this activity. Hope that helps. Good luck!