Alertdialog
안쪽에 Asynctask
을 표시해야하지만 throws 예외는 표시되지 않습니다.안드로이드 안의 asynctask에 경고 대화 상자가 있습니다.
05-13 14:59:35.522: WARN/System.err(1179): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
감사합니다.
Alertdialog
안쪽에 Asynctask
을 표시해야하지만 throws 예외는 표시되지 않습니다.안드로이드 안의 asynctask에 경고 대화 상자가 있습니다.
05-13 14:59:35.522: WARN/System.err(1179): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
감사합니다.
백그라운드 스레드에서 UI를 조작 할 수 없습니다. 이를 위해 AsyncTask의 핸들러 또는 onPre/Post 메소드를 사용하십시오.
내 생각에 this이 문제 일 수 있습니다. doInBackground 내부에서 대화 상자를 표시 할 수 없습니다.
대화 상자를 doInBackground가 아닌 onPostExecute() 메소드에 표시하십시오. 당신이 바로() doInBackground에서) publishProgress를 (전화) (onProgressUpdate에서 UI로 조작 할 수
을하는 데 도움이
희망.
backGround 스레드에서 UI 스레드에 도달하는 데 문제가 없습니다 (더 명확 : doInBackground() 메소드에서). 귀하의 컨텍스트에서 runOnUiThread()
메소드를 실행하기 만하면됩니다. 제 경우에는 doInBackground()
시체에서 부릅니다.
ContactsViewerActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(ContactsViewerActivity.this);
builder.setTitle("Connection problem..")
.setMessage("Could not connect to " + url + ", " +
"try changing your host in the settings to default one :" +
getResources().getString(R.string.default_server_ip) + ":" +
getResources().getString(R.string.default_server_port))
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});