2013-06-03 180 views
0

我试图让我的第一个活动睡眠5秒,然后开始一个新的活动,但是当我测试应用程序时。该应用程序崩溃。 这是我的logcatAndroid应用程序因线程崩溃

06-03 12:40:28.915: E/AndroidRuntime(1480):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618) 
06-03 12:40:28.915: E/AndroidRuntime(1480):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417) 
06-03 12:40:32.655: I/Choreographer(1480): Skipped 56 frames! The application may be doing too much work on its main thread. 
06-03 12:40:33.675: I/Process(1480): Sending signal. PID: 1480 SIG: 9 

以下是我的代码。

  Thread timer = new Thread(){ 
    public void run(){ 
     try{ 
      sleep(5000); 
     Intent openStartingPoint = new Intent(MainActivity.this, Menu.class); 
      startActivity(openStartingPoint); 
      finish(); 
     } 
     catch(InterruptedException e){ 

      e.printStackTrace();   

     } 


    } 


    }; 

timer.start(); 

} 
+1

http://developer.android.com/training/articles/perf-anr.html。在线程中使用睡眠是一个糟糕的设计。检查链接的敌人详情。使用一个处理程序或runOnUiThread – Raghunandan

回答

0

您可以使用此代码,可以帮助ü..

Thread timer = new Thread(){ 
public void run(){ 
    try{ 
     sleep(5000); 
     MainActivity.this.runOnUiThread(new Runnable() { 
     @Override 
     public void run() {         
      Intent openStartingPoint = new Intent(MainActivity.this, Menu.class); 
      MainActivity.this.startActivity(openStartingPoint); 
      MainActivity.this.finish(); 
      }); 

    } 

    } 
    catch(InterruptedException e){ 

     e.printStackTrace();   

    } 


} 


    }; 

timer.start(); 

}