简体   繁体   English

Android App因线程崩溃

[英]Android App crashing due to thread

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. 我正在尝试使我的第一个活动休眠5秒钟,然后在测试应用程序时开始新的活动。 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();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM