내 응용 프로그램은 주 스레드에서 네트워크 호출을하기 때문에 실패하고 있다는 것을 제외하고는 모든 Android 버전에서 정상적으로 작동합니다. 내 코드는 url.openStream()
에 실패하고 나는이 스레드를 별도로 호출해야한다고 생각한다. 또한이 클래스는 Utilities
이므로 응용 프로그램의 많은 부분에서 사용하는 함수를 참조 할 수 있습니다. 나는 이것이 잘못되었다는 것을 확신하지만, 당시 내가 아는 것이 전부였다. 누군가가 시간을내어 기꺼이이 일을 어떻게 수행 했어야하고 openStream
전화를 AsyncTask
전화로 감쌀 수 있는지 보여 주길 바란다. 귀하의 도움에 미리 감사드립니다. 또한, 나는 지난 며칠 동안 혼자서 알아 내려고 노력했다.Android Help with AsyncTask
class Utilities {
static XMLReader xr;
static URL url;
private final static int CHUNK_SIZE = 32 * 1024;
static byte[] _fileIOBuffer = new byte[CHUNK_SIZE];
static String DBGetOnlineVersionNumber(final Activity activity){
final String version = null;
try {
/* Create a URL we want to load some xml-data from. */
String location = activity.getString(R.string.version_file_location);
url = new URL(location);
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader*/
final XMLVersionReader myExampleHandler = new XMLVersionReader();
xr.setContentHandler(myExampleHandler);
xr.parse(new InputSource(url.openStream())); //Fails here
/* Parsing has finished. */
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
return version;
}
실제로 원하는 모든 것이 문자열 인 경우 활동 참조를 전달하는 것은 좋지 않은 생각입니다. – dmon