启动闪屏活动 [英] start Splash screen activity

查看:255
本文介绍了启动闪屏活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个使用闪屏。我至今写这一个code,但谁能告诉我这到底是怎么丢失的!?

I want to write a code that uses the splash screen .I have written this so far, but Can anyone tell me what is the missing here!?

下面是我的主要code:

here is my main code:

package com.example.splash;

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

public class MainActivity extends Activity {

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


    }



} 

和这里是我泼活动code:

and here is my splash activity code:

package com.example.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class splashscreen extends Activity {

protected int _splashTime = 5000; 

    private Thread splashTread;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splashh);
             final splashscreen sPlashScreen = this; 

                splashTread = new Thread() {
                    @Override
                    public void run() {
                        try {                   
                            synchronized(this){
                                wait(_splashTime);
                            }

                        } catch(InterruptedException e) {} 
                        finally {
                            finish();

                            Intent i = new Intent();
                            i.setClass(sPlashScreen,MainActivity.class);
                            startActivity(i);

                            //stop();
                        }
                    }
                };


                splashTread.start();

    }

问题是我不知道怎么告诉我主要去色斑的活性,如果我用一个意图我会停留在无限循环。

The problem is I do not know how to tell my main to go splash activity , if I use an intent I would stuck on infinite loop.

推荐答案

您可以简单地使用这样的:

You can simply use this:

 Handler handler=new Handler();
        handler.postDelayed(new Runnable()
        {               
            @Override
            public void run() 
            {
                Intent intent = new Intent(SplashViewController.this,HomeViewController.class);
                startActivity(intent);
                SplashViewController.this.finish();                         
            }
        }, 3000);

这篇关于启动闪屏活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆