我的Android應用程序中的Java線程有問題。我的嵌套線程阻止我的用戶界面,我該如何解決這個問題?線程塊我的Android UI
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);
}
}
你能幫助我嗎?我literaly卡;)
+1,我看到很多人在'Thread'對象上調用'run()'而不是'start()'。 ( – mre 2011-06-02 19:54:08
我也是。標準錯誤真的。 – aioobe 2011-06-02 19:54:49
好吧,我的java expiriance是2天長。謝謝你的回答。如果這有助於我的錯誤發佈:) – Knobik 2011-06-02 20:03:38