내 프로젝트에서 JSON (BaseAdapter를 통해)에서 표시된 데이터로 목록보기를 만들었습니다. 어댑터의 초기화에서 JSON for Progress Dialog가 표시된 AsyncTask를 초기화합니다.JSON이 Android Lollipop에서 작동하지 않습니다.
모든 안드로이드 버전에서 모든 것이 잘 작동하지만 안드로이드 롤리팝에서는 로딩이 멈추지 않습니다.
private class NewsJsonAsync extends AsyncTask<Void, Void, Boolean> {
private String mURLString = "http://json.com/json.json";
private ProgressDialog mProgressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setMessage(mContext.getString(R.string.dialog_loading_title));
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
Log.d("DO IN BACKGROUND", "BEFORE TRY/CATCH");
try {
String stream = streamManager();
jsonManager(stream);
} catch (JSONException e) {
e.printStackTrace();
Log.d("JSON EXCEPTION HERE", e.getLocalizedMessage());
return false;
} catch (IOException e) {
e.printStackTrace();
Log.d("IO EXCEPTION HERE", e.getLocalizedMessage());
return false;
}
Log.d("DO IN BACKGROUND", "AFTER TRY/CATCH");
return true;
}
@Override
protected void onPostExecute(Boolean result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (result == true) {
notifyDataSetChanged();
mProgressDialog.dismiss();
} else {
mProgressDialog.dismiss();
}
}
private String streamManager() throws IOException {
URL url = new URL(mURLString);
InputStream stream = url.openStream(); //open the data stream
byte[] bytes = new byte[stream.available()];
String getBytes = ""; //holds the data recived for the server in their raw form
int countBytes; //indicator for the amount of bytes left
while ((countBytes = stream.read(bytes)) > -1) { //while the stream size is more then -1 (while there is still data)
getBytes += new String(bytes,0,countBytes); //add the data to the string
}
stream.close();
return getBytes;
}
protected void jsonManager (String data) throws JSONException {
JSONArray jsonArray = new JSONArray(data); //call the JSON GENERAL array
String title = "";
String subtitle = "";
int size = jsonArray.length();
for (int i = 0; i < size; i++) {
JSONObject jsonArticle = jsonArray.getJSONObject(i);
title = jsonArticle.getString(Enums.JSON_TITLE.getValue());
subtitle = jsonArticle.getString(Enums.JSON_SUBTITLE.getValue());
mArray.add(new NewsListWithDB(title, subtitle)));
}
"TRY/CATCH 시작하기"에 로그가 표시되지 않습니다. 나는 그것이 내가 반복
12-10 09:38:38.991: I/art(23270): Background sticky concurrent mark sweep GC freed 263748(8MB) AllocSpace objects, 0(0B) LOS objects, 33% free, 10MB/16MB, paused 1.617ms total 107.675ms
가 그 예술이 될 수 얻을 하나의 메시지와 함께 할 수있는 뭔가가 있다고 생각 로그 고양이는 문제의 원인에 따라? 나는 어떻게해야합니까?
'ProgressDialog.show (context, title, message)'를 사용해 보셨습니까? 참조를 확인하십시오 [here] (http://developer.android.com/reference/android/app/ProgressDialog.html) – Joe3112
JSON이로드되지 않거나 대화 상자에 문제가 없습니다 ... – EladB
Ok 질문에 오해가 있었음에 틀림 없습니다. 문제를 더 잘 설명해 주시겠습니까? 그래서 문제는 JSON이 전혀로드되지 않는다는 것입니다. – Joe3112