asynctask가 실행되기 전에 연결과 올바른 연결을 확인하지만 때로는 응용 프로그램이 다운되는 경우가 있습니다. UI 스레드에서 생각하기 때문입니다. AsyncTask에 코드를 추가하면 응용 프로그램이 항상 중단됩니다. 어떤 해결책? 에서 onCreate 방법에AsyncTask의 연결 확인
:
if(connectionOK())
{
try {
url = new URL(bundle.getString("direccion"));
con = (HttpURLConnection) url.openConnection();
if(con.getResponseCode() == HttpURLConnection.HTTP_OK)
{
Tarea tarea = new Tarea(this);
tarea.execute();
}
else
{
con.disconnect();
//show alertdialog with the problem
direccionInvalida();
}
} catch (Exception e){e.printStackTrace();}
}
else
{
//show alertdialog with the problem
notConnection()
}
AsyncTask를 게시 할 수 있습니까? 어디에서 연결을 확인합니까? –
logcat/stacktrace에 오류를 표시 할 수 있습니까? –