0

アプリケーションにスプラッシュ スクリーンを含めた後、アプリケーションが読み込まれないという問題が発生しています。これは、SplashScreen.java とマニフェスト ファイルのコードです。何が欠けているのかわかりません。私はこれを数回繰り返しましたが、エラーを見つけることができません。私は同様の投稿を行ってきましたが、答えを見つけることができました。助けてください

    public class SplashScreen extends Activity {
private long ms=0;
    private long splashTime=2000;
private boolean splashActive = true;
private boolean paused=false;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
     Thread mythread = new Thread() {
    public void run() {
        try {
            while (splashActive && ms < splashTime) {
                if(!paused)
                    ms=ms+100;
                sleep(100);
            }
        } catch(Exception e) {}
        finally {
            Intent intent = new Intent(SplashScreen.this, TotalControl.class);
            startActivity(intent);
        }
        }
};
mythread.start(); 
}

マニフェスト ファイルは次のとおりです。

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.tvganesh.totalcontrol.SplashScreen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
           <activity
        android:name="com.tvganesh.totalcontrol.TotalControl"
        android:label="@string/app_name" >
    </activity>
</application>

表示されるスプラッシュ スクリーンの後、TotalControl.class に切り替えることになっています。しかし、「アプリケーションが予期せず停止しました」というメッセージが表示されます

不足しているものを教えてもらえますか?

4

3 に答える 3

1

Thread.sleep を使用しないでください。100 ミリ秒後に正確に再起動するという保証はありません。代わりにハンドラーを使用します。

getWindow().getDecorView().getHandler().postDelayed(new Runnable()
    {

        @Override
        public void run()
        {
            Intent intent = new Intent(SplashScreen.this, TotalControl.class);
            startActivity(intent);
        }
    }, splashTime);
于 2013-05-29T07:48:40.197 に答える
1

これでうまくいくと思います スプラッシュを表示するためにスレッドを使用しないでください。

public class SplashScreen extends Activity {

        protected int _splashTime = 5000; 

        private Thread splashTread;
        MyCount counter = new MyCount(4000, 4000);
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);

            counter.start();
        }
         public class MyCount extends CountDownTimer
         {
             public MyCount(long csecond, long countDownInterval) 
             {
                  super(csecond, countDownInterval);
             }

            @Override
            public void onFinish() {
                finish();
                Intent intent = new Intent();
                intent.setClass(SplashScreen.this, TotalControl.class);
                startActivity(intent);

            }

            @Override
            public void onTick(long arg0) {

            }
       }
    }
于 2013-05-29T07:49:49.307 に答える
0

私は問題を解決しました。これは AndEngine の既知のバグのようで、マニフェスト ファイルに次の行を追加して修正します。

android:configChanges="orientation|screenSize"

ご助力いただきありがとうございます。

于 2013-05-29T16:48:19.663 に答える