2014-01-18 91 views
0

我爲新到Android編程 我試圖開發一個簡單的程序中出現空白屏幕後 和5秒後,我的主要活動開始 但問題是當我啓動應用程序後5 - 6秒它顯示錯誤 我編程的XML和我的佈局是正確的 我的應用程序平臺是2.2 froyo 和我運行它在2.3.6 主要活動是加一減一活動 請告訴我它在很多程序中發生了什麼事無法在Android應用程序打開我的下一個屏幕5秒鐘

在此主要活動開始後第一個活動的代碼小號

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); //splash is a blank activity which changes after 5 sec 
    Thread timer = new Thread() { 
     public void run(){ 

      try{ 
       sleep(5000);  
      }catch(InterruptedException e){ 
       e.printStackTrace(); 
      }finally{ 
       Intent newtask = new Intent("com.example.newscreentask.newacivity"); 
       startActivity( newtask); 

      } 
     } 

    }; 
    timer.start(); 

}}

+0

你必須提供你的代碼和logcat輸出。 – FWeigl

+0

試試Intent newTask = new Intent(MainActivity.this,newActivity.class); –

+0

提示:除非您的應用需要在運行之前下載/讀取一些初步數據,否則通常不推薦使用splashscreen。 –

回答

1

變化:

Intent newtask = new Intent("com.example.newscreentask.newacivity"); 
       startActivity( newtask); 

到:

Intent newtask = new Intent(this,newacivity.class); 
       startActivity( newtask); 

還可以使用handler.postDelayed代替

new Handler().postDelayed(new Runnable() { 

       @Override 
       public void run() { 
        Intent newtask = new Intent(MainActivity.this,newacivity.class); 
        startActivity( newtask); 
       } 
      }, 5000); 
相關問題