【问题标题】:Android App crashing due to threadAndroid App由于线程而崩溃
【发布时间】:2013-06-03 12:42:30
【问题描述】:

我试图让我的第一个活动休眠 5 秒钟,然后开始一个新活动,但是当我测试应用程序时。该应用程序正在崩溃。 这是我的日志猫

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();

}

【问题讨论】:

标签: java android multithreading crash


【解决方案1】:

您可以使用此代码,它可能对您有所帮助..

  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();

}

【讨论】:

    猜你喜欢
    • 2022-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 2013-11-15
    • 2014-05-23
    • 1970-01-01
    相关资源
    最近更新 更多