程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了线程阻止了我的Android UI大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决线程阻止了我的Android UI?

开发过程中遇到线程阻止了我的Android UI的问题如何解决?下面主要结合日常开发的经验,给出你关于线程阻止了我的Android UI的解决方法建议,希望对你解决线程阻止了我的Android UI有所启发或帮助;

您需要使用.start()而不是.run()。也就是说,更换

nested.run();

nested.start();

run这只是一个普通方法。start()实际上是产生一个新线程并随后运行的方法run

解决方法

我的Android应用程序中的Java线程有问题。我的嵌套线程阻塞了我的UI,我该如何解决?

@H_221_2@myClass.java

package com.knobik.gadu;

import android.util.Log;

public class MyClass {

    public void StartTheThread() {

        Thread nested = new Thread( new nestedThread() );
        nested.run();
    }

    private class nestedThread implements Runnable {

        public void run() {

            while (true) {
                Log.d( "DUPA!","debug log SPAM!!" );
            }

        }

    }

}

这就是我的运行方式:

package com.knobik.gadu;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.httpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.httpGet;
import org.apache.http.impl.client.basicResponseHandler;
import org.apache.http.impl.client.DefaulthttpClient;

import android.app.Activity;
import android.os.bundle;
import android.util.Log;
import android.view.View;

public class AndroidGadu extends Activity {
    public static final String LogAct = "AndroidGadu";

    public void OnClickTest(View v) {

        MyClass test = new MyClass();
        test.StartTheThread();

    }


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceStatE) {
        super.onCreate(savedInstanceStatE);
        setContentView(R.layout.main);



    }
}

你可以帮帮我吗?我真的卡住了;)

大佬总结

以上是大佬教程为你收集整理的线程阻止了我的Android UI全部内容,希望文章能够帮你解决线程阻止了我的Android UI所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。