不支持德precated线程方法 [英] deprecated thread methods are not supported

查看:142
本文介绍了不支持德precated线程方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个项目,我需要显示的主页上,当主页显示,在这之后,或继续与3〜5秒我的其他受欢迎的自定义对话框显示。但做的是,出现下列错误,但我的应用程序不会停止工作.. LogCat中显示这些错误。 应用code:

 最后一个对话框D =新的对话框(Main.this);
    d.setContentView(R.layout.SplashScreen);
    螺纹splashTread =新的Thread(){
        @覆盖
        公共无效的run(){
            尝试 {
                d.show();

                INT等待= 0;
                而(_active&安培;及(等待&所述; _splashTime)){
                    睡眠(100);
                    如果(_active){
                        等待+ = 100;
                    }
                }
            }赶上(InterruptedException异常E){
                // 没做什么
            } 最后 {
                d.cancel();
                    停止();
            }
        }
    };
    splashTread.start();
}

@覆盖
公共布尔的onTouchEvent(MotionEvent事件){
    如果(event.getAction()== MotionEvent.ACTION_DOWN){
        _active = FALSE;
    }
    返回true;
}
 

在LogCat中的错误:

  12-30 14:54:54.044:E /全球(1232):不支持德precated线程方法。
12-30 14:54:54.044:E /全球(1232):java.lang.UnsupportedOperationException。
12-30 14:54:54.044:E /全球(1232):在java.lang.VMThread.stop(VMThread.java:85)
12-30 14:54:54.044:E /全球(1232):在java.lang.Thread.stop(Thread.java:1280)
12-30 14:54:54.044:E /全球(1232):在java.lang.Thread.stop(Thread.java:1247)
12-30 14:54:54.044:E /全球(1232):在com.droidnova.android.SplashScreen $ 1.运行(SplashScreen.java:35)
 

解决方案

在Android中它能够更好地使用处理程序管理​​的的Runnable

创建一个处理程序实例

 处理程序处理程序=新的处理程序();
 

创建一个可运行的线程

 可运行可运行=新的Runnable(){

        @覆盖
        公共无效的run(){
            Log.d(可运行开始,内部运行);
            handler.removeCallbacks(可运行);
            handler.postDelayed(可运行,1000);
        }
    };
 

和开始使用处理器可运行

  handler.postDelayed(可运行,1000);
 

和停止了Runnable使用

  handler.removeCallbacks(可运行);
 

I am making one project where i need to display Home page and when home page displays, after that or continue with that 3 to 5 seconds my other welcome custom dialog is display. but making that, following error occurs but my application doesn't stop working.. LogCat displays these errors. Application Code:

  final Dialog d=new Dialog(Main.this);
    d.setContentView(R.layout.SplashScreen);
    Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {
                d.show();

                int waited = 0;
                while(_active && (waited < _splashTime)) {
                    sleep(100);
                    if(_active) {
                        waited += 100;
                    }
                }
            } catch(InterruptedException e) {
                // do nothing
            } finally {
                d.cancel();
                    stop();
            }
        }
    };
    splashTread.start();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
}

The error in LogCat:

12-30 14:54:54.044: E/global(1232): Deprecated Thread methods are not supported.
12-30 14:54:54.044: E/global(1232): java.lang.UnsupportedOperationException.
12-30 14:54:54.044: E/global(1232):     at java.lang.VMThread.stop(VMThread.java:85)
12-30 14:54:54.044: E/global(1232):     at java.lang.Thread.stop(Thread.java:1280)
12-30 14:54:54.044: E/global(1232):     at java.lang.Thread.stop(Thread.java:1247)
12-30 14:54:54.044: E/global(1232):     at com.droidnova.android.SplashScreen$1.run(SplashScreen.java:35)

解决方案

In Android its better to use Handler for managing the Thread and Runnables

Create an Handler instance

Handler handler = new Handler();

Create a Runnable thread

Runnable runnable = new Runnable() {

        @Override
        public void run() {
            Log.d("runnable started", "inside run");
            handler.removeCallbacks(runnable);
            handler.postDelayed(runnable, 1000);
        }
    };

And start the Runnable using Handler

handler.postDelayed(runnable, 1000);

And to stop the Runnable use

handler.removeCallbacks(runnable);

这篇关于不支持德precated线程方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆