应用程序未在启动画面后加载

时间:2013-05-29 07:33:49

标签: android android-intent android-manifest splash-screen

我遇到的问题是,在将Splash屏幕包含到应用程序后,应用程序无法加载。这是SplashScreen.java和amp;的代码。清单文件。我不确定我错过了什么。我已经过了好几次,无法发现错误。我已经找到了类似的帖子,但可以找到答案。请帮忙

    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。但我收到消息“应用程序意外停止”

你能让我知道我错过了什么吗?

3 个答案:

答案 0 :(得分:1)

不要使用Thread.sleep - 你不能保证它会在100ms之后再次启动。改为使用处理程序:

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

        @Override
        public void run()
        {
            Intent intent = new Intent(SplashScreen.this, TotalControl.class);
            startActivity(intent);
        }
    }, splashTime);

答案 1 :(得分: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) {

            }
       }
    }

答案 2 :(得分:0)

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

android:configChanges="orientation|screenSize"

感谢您的帮助。