应用程序关闭asynch任务,关于方向更改:android

时间:2012-08-22 10:11:19

标签: android android-asynctask

我正在使用异步任务进行一些后台操作,因为在后台进行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());
    }

}

2 个答案:

答案 0 :(得分:0)

用户showdialog(id)功能,用于创建对话框,特别是在屏幕方向改变时。更多细节是here

答案 1 :(得分:0)

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

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