0

我遇到了一个问题,即在将启动画面包含到应用程序后应用程序无法加载。这是 SplashScreen.java 和 Manifest 文件的代码。我不确定我错过了什么。我已经检查了好几次,但无法发现错误。我已经浏览过类似的帖子,但可以找到答案。请帮忙

    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

我认为这对你 有用 不要使用线程来显示飞溅。

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 回答
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 回答
0

我已经解决了这个问题。这似乎是 AndEngine 中的一个已知错误,修复方法是将以下行添加到 Manifest 文件

android:configChanges="orientation|screenSize"

感谢你的帮助。

于 2013-05-29T16:48:19.663 回答