I'm trying to make my first activity sleep for 5 seconds and then start a new activity but when I'm testing the application. The app is crashing. Here is my logcat
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
And below is my code.
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();
}
You may use this code, it may help u..
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.