-1

这是我下面的代码,它从服务器获取 xml 响应我如何在这段代码中设置请求超时计时器?如果服务器没有响应我的应用程序返回异常我是否在下面的代码中设置计时器所以如果服务器在 15 秒异常调用中没有响应

public static   String[][] AgAppXMLParser( String parUrl) {



    String _node,_element;
    String[][] xmlRespone = null;
    try {

            String url = www.xyz.com;
            URL finalUrl = new URL(url);    


            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(new InputSource(finalUrl.openStream()));
            doc.getDocumentElement().normalize();

            NodeList list=doc.getElementsByTagName("*");
            _node=new String();
            _element = new String();
            xmlRespone = new String[list.getLength()][2];

            //this "for" loop is used to parse through the
            //XML document and extract all elements and their
            //value, so they can be displayed on the device

            for (int i=0;i<list.getLength();i++)
                {
                    Node value=list.item(i).      getChildNodes().item(0);
                    _node=list.item(i).getNodeName();
                    _element=value.getNodeValue();
                    xmlRespone[i][0] = _node;
                    xmlRespone[i][1] = _element;

                }//end for

        }//end try











    catch (Exception e)
    {
      flag=false;
      Log.e(LOG_TAG, "CONNECTION ERROR   SERVER NOT RESPONDING", e);
    } 



    return xmlRespone;         

}
4

1 回答 1

0

为此,您需要实现Timer ...请参阅下面的参考链接...

如何在android中设置计时器

Android:如何使用计时器

Android中的计时器

希望对你有帮助...

于 2012-09-19T11:04:34.107 回答