1

我已经为android应用程序中的加载页面添加了启动屏幕的代码,但没有任何改变,任何人都可以解决这个问题吗?

这是我的代码:

Thread splashThread = new Thread() {
        @Override
        public void run() {
           try {
              int waited = 0;
              while (waited < 1000) {
                 sleep(100);
                 waited += 100;
              }
           } catch (InterruptedException e) {
              // do nothing
           } finally {

              Intent i = new Intent(Splash.this,Activity1.class);

              startActivity(i);
              finish();
           }
        }
     };
     splashThread.start();
    }
4

3 回答 3

1

使用 runOnUiThread从单独的线程启动活动:

 Splash.this.runOnUiThread(new Runnable() {
                public void run() {
                  // some code #3 (that needs to be ran in UI thread)
                  Intent i = new Intent(Splash.this,Activity1.class);

                 startActivity(i);
                 finish();
                }
            });
于 2012-11-05T09:57:14.750 回答
1

使用下面的代码:

Handler handler = new Handler();

        // run a thread after 2 seconds to start the home screen
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {

                // make sure we close the splash screen so the user won't come back when it presses back key

                finish();
                // start the home screen

                Intent intent = new Intent(SplashScreen.this, Home.class);
                SplashScreen.this.startActivity(intent);

            }

        }, 2000); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called

    }
于 2012-11-05T09:58:21.993 回答
0

通常,当您创建启动画面时,它是一个完全成熟Activity的负责显示某些 UI 的屏幕。

您可能应该做的是创建一个新类,该类Activity从其onCreate方法中扩展和运行您的 con。

在此之后,您应该更改清单文件以将活动定义为启动器,如下所示:

    <activity
        android:name=".SplashActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
于 2012-11-05T09:59:57.317 回答