public class GetAllEggs extends AsyncTask<Void, Void, List<Egg>> {
List<Egg> eggs;
Egg eg;
JSONParser jParser = new JSONParser();
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected List<Egg> doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
// Thread.sleep(5000);
/*** fetch data from server and save in the local db ***/
String url = Utils.alleggsofuser;
JSONObject jObject = jParser.makeHttpRequest(url, "GET", null);
//Log.d(DEBUG_TAG, "news response: " + response);
JSONArray categoryArray = new JSONArray(
jObject.getString("categories"));
for (int i = 0; i < categoryArray.length(); i++) {
/* make entries in the db */
JSONObject Category = categoryArray.getJSONObject(i);
eg=new Egg();
eg.setEggid(Category.getInt("eggid"));
eg.setApp_user_id(Category.getInt("app_user_id"));
eg.setEgg_query(Category.getString("egg_query"));
eg.setEgg_date_time(null);
eggs.add(eg);
/**/
}
/**/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// pBar.cancel();
}
return eggs;
}
protected void onPostExecute(List<Egg> result) {
// TODO Auto-generated method stub
}
List<Egg> eggs=new ArrayList();
new GetAllEggs().execute(eggs);
我希望鸡蛋能够获取GetAllEggs().execute()
返回的数据。
这样我就可以在另一个可以显示它的类中使用返回的蛋。
我正在尝试将返回的数据分配给新类中的列表。
由于程序的结构,我无法在postexecute()
执行操作
答案 0 :(得分:0)
我可以在后执行中调用ui线程,而不是从post执行到ui线程 runOnUiThread(new Runnable(){public void run(){}});