2

我按照stackoverflow用户的说法创建了启动画面,但仍然无法获得android应用程序的启动画面,我的代码是

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);

 // thread for displaying the SplashScreen
    Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                boolean active = false;
                while(active && (waited < 1000)) {
                    sleep(100);
                    if(active) {
                        waited += 100;
                    }
                }
            } catch(InterruptedException e) {
                // do nothing
            } finally {
                startActivity(new Intent(SplashScreenActivity.this,MainActivity.class));
                finish();
                //startActivity(new Intent("com.splash.com.MyApps"));
                //startActivity( new Intent(getApplicationContext(), Myapps.class));
            }
        }
    };
    splashTread.start();
}
4

3 回答 3

3

只需复制此文件并根据您的文件修改进行更改。

public class Splash extends Activity {

    private final int SPLASH_DISPLAY_LENGHT = 2000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splashscreen);

        /* New Handler to start the Menu-Activity 
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent mainIntent = new Intent(Splash.this,MainActivity.class);
                Splash.this.startActivity(mainIntent);
                Splash.this.finish();
            }
        }, SPLASH_DISPLAY_LENGHT);
    }
于 2012-11-06T10:04:09.060 回答
2

做这个...

@Override
    protected void onCreate(Bundle savedInstanceState) 
    {   
             mythread thread = new  mythread();
             thread.start();
        }
class mythread extends Thread
    {

        @Override
        public void run()
        {

            super.run();

            try
            {
                Thread.sleep(3000);

                    Intent i = new Intent(Splash_Screen.this,ArboristActivity.class);
                    finish();
                    startActivity(i);

            }
            catch (Exception e) 
            {
                Log.v("log",e.toString());
            }   
        }//End Run

    }

并将 splashScreenActivity 作为启动器活动放在清单文件中......就像这样......

<activity
            android:name="com.app.Login.Splash_Screen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>
于 2012-11-06T10:05:57.707 回答
1

Because you are initializing your active flag inside the run method with false, it will never enter in the while..it should be like..

boolean active = true;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);

 // thread for displaying the SplashScreen
Thread splashTread = new Thread() {
    @Override
    public void run() {
        try {
            int waited = 0;

            while(active && (waited < 1000)) {
                sleep(100);
                if(active) {
                    waited += 100;
                }
            }
        } catch(InterruptedException e) {
            // do nothing
        } finally {
            startActivity(new Intent(SplashScreenActivity.this,MainActivity.class));
            finish();
            //startActivity(new Intent("com.splash.com.MyApps"));
            //startActivity( new Intent(getApplicationContext(), Myapps.class));
        }
    }
};
splashTread.start();
}
于 2012-11-06T09:32:39.297 回答