AsyncTask无限循环

时间:2012-08-18 18:42:07

标签: android json android-asynctask

当我的程序在doInBackground()方法中时,我正在doInBackground()中从JSON API检索一些数据我的日志表明数据已被检索,而不是转到onPostExecute() doInBackground()仍在无限循环中运行。 我怎么能停止这个循环?

这是我的doInBackground()编码:

@Override
protected String doInBackground(String... DATA) {
    // TODO Auto-generated method stub
    TYPE = DATA[0];

if(TYPE=="reservation_page")
    {
        URL = DATA[1];
        jParser = new JsonParser();
        json = jParser.getJSONfromUrl(URL+memberId);
        try
        {
            JSONArray reservation = json.getJSONArray(TAG_RSVTION);
            for(int i = 0; i<reservation.length(); i++)
            {
                JSONObject r = reservation.getJSONObject(i);
                amount = r.getString(TAG_AMNT);
                gcpamount = r.getString(TAG_GCPAMNT);
                date1 = r.getString(TAG_DATE);
                month = r.getString(TAG_MNTH);
                year = r.getString(TAG_YEAR);
                time1 = r.getString(TAG_TIME);
                golfcourse_name = r.getString(TAG_GLFCRSNAME);
                no_of_player = r.getString(TAG_PLYRNO);

                HashMap<String, String> map = new HashMap<String, String>();

                map.put(TAG_AMNT, amount);
                map.put(TAG_GCPAMNT, gcpamount);
                map.put(TAG_DATE, date1);
                map.put(TAG_MNTH, month);
                map.put(TAG_YEAR, year);
                map.put(TAG_TIME, time1);
                map.put(TAG_GLFCRSNAME, golfcourse_name);
                map.put(TAG_PLYRNO, no_of_player);

                resvList.add(map);
                Log.v(TAG_LOG, "list: "+resvList);
            }
            Log.v(LoadingScreen.TAG_LOG, "reserv: "+reservation);
            Log.v(LoadingScreen.TAG_LOG, "name: "+golfcourse_name);
        }
        catch(JSONException e)
        {
            Log.v(LoadingScreen.TAG_LOG, String.valueOf(e));
        }
    }
    return null;
}

这是我的onPostExecute()编码:

protected void onPostExecute(String result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);

if(TYPE=="reservation_page")
    {
        Intent in = new Intent(context, MyReservation.class);
        in.putExtra(TAG_MBRID, memberId);
        in.putExtra(TAG_AMNT, amount);
        in.putExtra(TAG_GCPAMNT, gcpamount);
        in.putExtra(TAG_DATE, date1);
        in.putExtra(TAG_DAY, day);
        in.putExtra(TAG_MNTH, month);
        in.putExtra(TAG_YEAR, year);
        in.putExtra(TAG_TIME, time1);
        in.putExtra(TAG_GLFCRSNAME, golfcourse_name);
        in.putExtra(TAG_PLYRNO, no_of_player);
        context.startActivity(in);
    }
    progress.dismiss();
}

2 个答案:

答案 0 :(得分:2)

Blah ...... Blah ...... Blah ......

如果条件错误 ..应该是,

if(TYPE.equals("reservation_page"))

if(TYPE=="reservation_page")

使用.equals()的{​​{1}}比较两个字符串..

答案 1 :(得分:1)

您是否正在进入循环或者jParser.getJSONfromUrl(URL+memberId)可能会永远等待您的网址回复?只需运行你的调试器,找出错误就不应该是一个问题。