我是Android新手,我正在尝试使用UI-Thread,所以我写了一个简单的测试活动.但我认为我误解了一些东西,因为点击按钮 - 应用程序不再响应
public class TestActivity extends Activity {
Button btn;
int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
runThread();
}
});
}
private void runThread(){
runOnUiThread (new Thread(new Runnable() {
public void run() {
while(i++ < 1000){
btn.setText("#"+i);
try {
Thread.sleep(300);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}));
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试使用Android 4.4(Kit kat)在我的nexus 4上打开webview时,我会收到以下错误消息:
Calling View methods on another thread than the UI thread.;
java.lang.IllegalStateException: Calling View methods on another thread than the UI thread.
com.android.webview.chromium.WebViewChromium.createThreadException(WebViewChromium.java:268)
Run Code Online (Sandbox Code Playgroud)
自从我更新到Android 4.4我的Nexus 4.
multithreading android illegalstateexception android-4.4-kitkat webviewchromium