android 4.3 - BufferedReader显示Please Wait消息

时间:2017-07-10 07:01:37

标签: android

我有以下功能允许我的Android应用程序与Web服务器通信。但是,当我调用此代码时,应用程序会显示“请等待”消息,只有在加载新活动或按下后退按钮时才会消失。请等待来自哪里,如何避免出现?感谢

package util.sapa.sapacontainermanager5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

public class SimpleWebCalls {

    public String executeHttpGet(String serverIP, String nvp) {
        String lines="";
        serverIP="???????????";

        URL url = null;
        try {
            url = new URL("http://" + serverIP + "/WCF.aspx?" + nvp);


            HttpURLConnection conn = null;
            try {
                conn = (HttpURLConnection) url.openConnection();

                try {
                    conn.setRequestMethod("GET");

                    BufferedReader in = null;
                    try {
                        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                        StringBuffer sb = new StringBuffer("");
                        String line = "";
                        String NL = System.getProperty("line.separator");
                        while ((line = in.readLine()) != null) {
                            sb.append(line + NL);
                            lines+=line;
                        }
                        in.close();
                        return lines;

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } catch (ProtocolException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return "";
    }
}

上述类来自:

public String GetDataFromServer(String serverIP,String nvp) {   
     SimpleWebCalls tWebCall = new SimpleWebCalls();
     String sReturn="";
     sReturn= tWebCall.executeHttpGet(serverIP,nvp);
     return sReturn;
}

从上面调用上述函数:

String data="";
data="doAction=location&u=" + sess.getUserName()+
    "&p=" + sess.getPwd() + 
    "&uid=" + sess.getUserID() + 
    "&lf=" + sess.encodeStr(editScannedCode.getText().toString());              
result = sess.GetDataFromServer(serverIP,data);

1 个答案:

答案 0 :(得分:0)

follow this tutorial link它可能会对您有所帮助。

将GetDataFromServer()方法添加到doInBackground()方法中。