03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global:
Deprecated Thread methods are not supported.
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: java.lang.UnsupportedOperationException
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.VMThread.stop(VMThread.java:85)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.Thread.stop(Thread.java:1280)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.Thread.stop(Thread.java:1247)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at tech.androidstudio.handlerdemotimer.MainActivity.btnDaoJiShi(MainActivity.java:69)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invokeNative(Native Method)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invoke(Method.java:507)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.view.View$1.onClick(View.java:2139)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.view.View.performClick(View.java:2485)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.view.View$PerformClick.run(View.java:9080)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.os.Handler.handleCallback(Handler.java:587)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.os.Handler.dispatchMessage(Handler.java:92)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.os.Looper.loop(Looper.java:123)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.app.ActivityThread.main(ActivityThread.java:3683)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invokeNative(Native Method)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invoke(Method.java:507)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: java.lang.UnsupportedOperationException
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.VMThread.stop(VMThread.java:85)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.Thread.stop(Thread.java:1280)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.Thread.stop(Thread.java:1247)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at tech.androidstudio.handlerdemotimer.MainActivity.btnDaoJiShi(MainActivity.java:69)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invokeNative(Native Method)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invoke(Method.java:507)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.view.View$1.onClick(View.java:2139)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.view.View.performClick(View.java:2485)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.view.View$PerformClick.run(View.java:9080)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.os.Handler.handleCallback(Handler.java:587)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.os.Handler.dispatchMessage(Handler.java:92)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.os.Looper.loop(Looper.java:123)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at android.app.ActivityThread.main(ActivityThread.java:3683)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invokeNative(Native Method)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at java.lang.reflect.Method.invoke(Method.java:507)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-16 15:39:03.082 16179-16179/tech.androidstudio.handlerdemotimer E/global: at dalvik.system.NativeStart.main(Native Method)
原因:
现在Thread.stop()方法已经过时了。不支持使用,
解决方法:
现在都是在run方法中使用标记。然后通过设置标记来更改线程的状态。
例如,这里的倒计时的代码:
package tech.androidstudio.handlerdemotimer; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements