3

我希望当用户打开应用程序播放歌曲并且歌曲完成时会触发一个新活动,我放了一个跳过按钮以允许用户停止歌曲并转到下一个活动,这是代码

timer = new Thread() {
            public void run() {
                try {
                    sleep(13000);
                } catch (InterruptedException e) {
                    // TODO: handle exception
                } finally {
                    Intent openStartingPoing = new Intent(
                            "com.localizedbasedcompetition.SIGNIN");// action
                                                                    // name
                    startActivity(openStartingPoing);
                }
            }
        };
        timer.start();

这是跳过按钮的onclick

public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.bSplashSkip:
            timer.stop();
            Intent openStartingPoing = new Intent(
                    "com.localizedbasedcompetition.SIGNIN");// action name
            startActivity(openStartingPoing);
            break;

        default:
            break;
        }
    }

并且该代码运行良好,我的意思是如果我单击跳过按钮歌曲停止并且新活动开始,但我的问题是即使也很好,我有一个异常(但应用程序仍然有效)并且应用程序是

07-05 13:34:19.687: E/global(26114): Deprecated Thread methods are not supported.
07-05 13:34:19.687: E/global(26114): java.lang.UnsupportedOperationException
07-05 13:34:19.687: E/global(26114):    at java.lang.VMThread.stop(VMThread.java:85)
07-05 13:34:19.687: E/global(26114):    at java.lang.Thread.stop(Thread.java:1280)
07-05 13:34:19.687: E/global(26114):    at java.lang.Thread.stop(Thread.java:1247)
07-05 13:34:19.687: E/global(26114):    at com.localizedbasedcompetition.Splash.onClick(Splash.java:73)
07-05 13:34:19.687: E/global(26114):    at android.view.View.performClick(View.java:2552)
07-05 13:34:19.687: E/global(26114):    at android.view.View$PerformClick.run(View.java:9229)
07-05 13:34:19.687: E/global(26114):    at android.os.Handler.handleCallback(Handler.java:587)
07-05 13:34:19.687: E/global(26114):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-05 13:34:19.687: E/global(26114):    at android.os.Looper.loop(Looper.java:130)
07-05 13:34:19.687: E/global(26114):    at android.app.ActivityThread.main(ActivityThread.java:3701)
07-05 13:34:19.687: E/global(26114):    at java.lang.reflect.Method.invokeNative(Native Method)
07-05 13:34:19.687: E/global(26114):    at java.lang.reflect.Method.invoke(Method.java:507)
07-05 13:34:19.687: E/global(26114):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
07-05 13:34:19.687: E/global(26114):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
07-05 13:34:19.687: E/global(26114):    at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

7

使用 timer.interrupt() 而不是 .stop()。正如您的日志所说,不推荐使用 Thread.stop() 。

于 2012-07-05T10:42:06.287 回答