0

我正在使用异步任务来执行一些后台操作,因为在后台执行 xml 解析,它运行良好,但是在更改 android 设备的来源时,它会导致强制关闭,我在它上面谷歌,但没有任何相应或可以说无法探索我的自我,请任何人对我的分享有想法..我会感谢你..

     @Override
protected void **onPreExecute()** {


    if(refreshFlage)
    {
        Log.i("refreshFlage","refreshFlage");
        dialog = new ProgressDialog(ReplyForm.replyform);
        dialog.setMessage("Processing...");
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();
    }
    else 
    {
        dialog = new ProgressDialog(QuestionScreen.questionscreen);
        dialog.setMessage("Processing...");
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();  
    }


}

@Override
protected void **onPostExecute**(final Boolean success) {
    dialog.cancel();


    try {
        java.lang.System.gc();
    } catch (Exception e) {
        e.printStackTrace();
    }

    }else {

 try{

    }

}
     catch (NullPointerException e) {
        // TODO: handle exception
    }
 }
}

@Override
protected Boolean **doInBackground**(final String... args) {
    getQuestionsMethod();


    return null;
}

private void getQuestionsMethod() {
    // TODO Auto-generated method stub

    HttpResponse response = null;
    InputStream is = null;




        JSONObject jsonObj = new JSONObject(result);

        JSONObject jobj = jsonObj.getJSONObject("question");

        group_subject = jobj.getString(TAG_SUBJECT);
        question_id = jobj.getString(TAG_QUESTIONID);
        author_name = jobj.getString(TAG_AUTHORNAME);
        lastpost_date = jobj.getString(TAG_LASTPOSTDATE);
        replies = jobj.getString(TAG_REPLIES);
        newPost = jobj.getString(TAG_NEWPOST);
        userCanReply = jobj.getString(TAG_USERCANREPLY);

        poll = jobj.getString(TAG_POLL);

        HashMap<String, Object> groupdetailData = new HashMap<String, Object>();
        groupdetailData.put(TAG_SUBJECT, group_subject);
        groupdetailData.put(TAG_QUESTIONID, question_id);
        groupdetailData.put(TAG_AUTHORNAME, author_name);
        groupdetailData.put(TAG_LASTPOSTDATE, lastpost_date);
        groupdetailData.put(TAG_REPLIES, replies);
        groupdetailData.put(TAG_POLL, poll);
        groupdetailData.put(TAG_NEWPOST, newPost);
        groupdetailData.put(TAG_USERCANREPLY, userCanReply);

        int arrayCount = questiondetailarraylist.size();

        if (arrayCount > 0) {
            questiondetailarraylist.clear();
        }






        if (poll.equalsIgnoreCase("true")) {
            pollmulti = jobj.getString(TAG_POLLMULTI);
            pollsubject = jobj.getString(TAG_POLLSUBJECT);
            Pollid = jobj.getString(TAG_POLLID);

            groupdetailData.put(TAG_POLLMULTI, pollmulti);
            groupdetailData.put(TAG_POLLSUBJECT, pollsubject);
            groupdetailData.put(TAG_POLLID, Pollid);

            //mDbHelper.insertPollfield(questionid, pollmulti, pollsubject, Pollid);



            groupdetailData.put("PollTrueData", pollTrueVector);
            //System.out.println("after poll method..");
        }


        //System.out.println(groupdetailData.size());
        questiondetailarraylist.add(groupdetailData);
        //System.out.println("11111111111111111");

    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }

}



        answersHashMap.put("vectorArray", vectorArray);

        answersHashMap.put("lastUpdateValue", lastUpdateValue);

    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }

}
4

2 回答 2

0

用于创建对话框的用户 showDialog(id) 函数,特别是当屏幕方向改变时。更多细节在这里

于 2012-08-22T10:18:58.373 回答
0

在方向改变时,活动被销毁并重新创建。

您需要通过将文件中的属性添加到当前活动来处理此android:configChanges="orientation"问题AndroidManifest

于 2012-08-22T10:20:29.870 回答