我使用排球庫從JSON格式的api獲取數據,它的工作原理就像一個魅力。我要求提供JSON文件,我收到了回覆,我解析了這個問題,並在活動中對這些觀點進行了迴應和大衆化。Android排空保存json數據以字符串進行共享(onPostExecute方法排空?)
現在,我有一個按鈕來分享數據使用Intetnt.ACTION_SEND和putExtra(Intent.EXTRA_TEXT),它將字符串作爲第二個參數。
問題是,我製作了一個字符串變量,並將該數據添加到排列在響應方法中的字符串變量中。但是隨着排列使得從api獲取數據的新線程不被更新並且Intetnt.EXTRA_TEXT發送空字符串。
我想問一下,如果有什麼simulator到onPostExecute方法排氣嗎?在線程完成處理後,我可以將數據設置爲某些變量。或任何其他方法來做同樣的事情。
JsonObjectRequest jsObjRequest = new JsonObjectRequest(
Request.Method.GET, bookSearchString, null,
new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
try {
JSONArray bookArray = response
.getJSONArray("items");
JSONObject bookObject = bookArray.getJSONObject(0);
try {
bookSelfLink = bookObject.getString("selfLink");
JsonObjectRequest newJsObjRequest = new JsonObjectRequest(
Request.Method.GET, bookSelfLink, null,
new Response.Listener<JSONObject>() {
public void onResponse(
JSONObject response) {
try {
JSONObject newBookObject = response
.getJSONObject("volumeInfo");
try {
dBookPages.setText("Pages - "
+ newBookObject
.getString("pageCount"));
eMailText = eMailText + newBookObject
.getString("pageCount"));
} catch (JSONException jse) {
dBookPages
.setText("Pages not found");
jse.printStackTrace();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(
VolleyError error) {
// TODO Auto-generated method
// stub
}
});
AppController.getInstance().addToRequestQueue(
newJsObjRequest, tag_json_obj);
} catch (JSONException jse) {
jse.printStackTrace();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
});
AppController.getInstance().addToRequestQueue(jsObjRequest,
tag_json_obj);
'onResponse'在UI上運行,發佈您的代碼! – mmlooloo 2014-09-19 16:00:50
好吧,給我幾分鐘 – 2014-09-19 16:06:43
我已經用代碼更新了que。 – 2014-09-19 16:13:21