0

メインアプリ画面の前に実行したいスプラッシュ画面があります。ただし、タイマーが終了すると、アプリケーションがクラッシュします。なぜこれが起こるのかについてのアイデアはありますか?前もって感謝します。

以下、参考にしたコード

public class Splash extends Activity {

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

        Thread timer = new Thread() {
            // Whatever is enclosed in the {} of method run(), runs when we
            // start the application
            public void run() {
                try {
                    sleep(2000);

                } catch (InterruptedException e) {
                    e.printStackTrace();

                } finally {

                    Intent openMainScreen = new Intent("com.package.Main_Screen");
                    startActivity(openMainScreen);

                }
            }
        };

        timer.start();
    }
}
4

4 に答える 4

1

この種のインテントを単純に使用してみませんか、

Intent openMainScreen = new Intent(Splash.this,Main_Screen.class);
startActivity(openMainScreen);

また、このようにマニフェストにアクティビティを追加したことを確認してください。

<activity android:name=".Main_Screen">
 </activity>
于 2012-12-06T11:58:27.353 に答える
0

以下のコードを書く

Intent openMainScreen = new Intent(this, MainActivity.class);
startActivity(openMainScreen);

それ以外の

Intent openMainScreen = new Intent("com.package.Main_Screen");
startActivity(openMainScreen);

そして、MainActivityをAndroidmanifest.xmlファイルに宣言します。

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

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

それはあなたの問題を解決します。

于 2012-12-06T11:58:05.683 に答える
0

startActivityから呼び出していますThread。から実行するUI thread必要があります。達成しようとしていることは、次の方法で簡単に実行できます。

    public class Splash extends Activity {
        Handler handler;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);
            handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    Intent openMainScreen = new Intent(Splash.this,
                            Main_Screen.class);
                    startActivity(openMainScreen);

                }
            }, 2000);
        }
    }
于 2012-12-06T12:02:09.370 に答える
0

このように呼び出す必要があります

Intent openMainScreen = new Intent(ClassName.this, MainActivity.class);
startActivity(openMainScreen);

そして、それをマニフェストファイルに登録する必要があります

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
于 2012-12-06T12:07:19.650 に答える