I have a problem with java Threads in my Android app. My nested thread blocks my UI, how can i resolve this?
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!!" );
}
}
}
}
and this is how i run it:
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);
}
}
Could you help me? I'm literaly stuck ;)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…