2013-04-13 126 views
0

我的應用程序似乎啓動正常,與啓動畫面和東西。但是當它睡了6秒,並且它應該進入主要活動時,該應用程序會崩潰任何幫助嗎?主要活動未開通

這裏是我的代碼(android.intent.action1.MAINACTIVIVTY,「動作」被故意更改爲「動作1」)

package com.hellhogone.multitools; 

import com.hellhogone.multitools.R; 

import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.Window; 
import android.view.WindowManager; 

public class Splash extends Activity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.splash); 

    MediaPlayer yo = MediaPlayer.create(Splash.this, R.raw.smusic); 
    yo.start(); 

    Thread timer = new Thread(){ 
     public void run(){ 
      try{ 
       sleep(6000); 
      }catch(InterruptedException e){ 
       e.printStackTrace(); 
      }finally{ 
       Intent h1 = new Intent("android.intent.action1.MAINACTIVITY"); 
       startActivity(h1); 
      } 
     } 
    }; 

    timer.start(); 
} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
    finish(); 
} 



} 
+0

這是一個粗略的猜測...你註冊你的下一個活動清單......如果不是剛剛註冊它那裏... –

+0

其註冊。 – WhiplashOne

回答

1

您不能從另一個線程比UI線程啓動活動。爲了避免這個問題,你可以使用runOnUiThread()

}finally{ 
     runOnUiThread(new Runnable() { 
      public void run() { 
       Intent h1 = new Intent("android.intent.action1.MAINACTIVITY"); 
       startActivity(h1); 
      } 
     }); 
    } 
+0

但它之前工作完美。 – WhiplashOne

+0

我仍然遇到與您的方法有關的錯誤。 :/ – WhiplashOne

+0

它與其他活動完美協調,而不是與主要活動一起使用。 – WhiplashOne