2013-05-29 32 views
0

我遇到了將啓動畫面包括到應用程序後未加載應用程序的問題。這是Manifest文件的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後。但我得到消息「應用程序意外停止」

你能讓我知道我失蹤了嗎?

+1

plz還添加logcat結果的問題,以獲得更多的幫助,我們 –

+0

我不記得logcat O/P,但我認爲問題發生在onResumeGame()。我正在使用AndEngine –

+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

我認爲這會爲你工作 不要使用線程來顯示啓動。

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) { 

      } 
     } 
    } 
0

我已經解決了這個問題。這似乎是在AndEngine一個已知的bug修復該問題下面一行添加到清單文件

android:configChanges="orientation|screenSize" 

感謝您的幫助。

相關問題