2

I am new to Android, but i know somewhat in Java, and Java EE While communicating with the Server(webservice) , it works fine with the response i am getting from it. But if there is any time delay more than 5 seconds, it is going to ANR. Now my question is how to check with my java functionality , to know whether the server is responding or not responding . Any ideas in this??

Even some Related examples will help me.

Code Snippet

Handler handler = new Handler(); 
handler.postDelayed(new Runnable() { 
    public void run() { 
             // Problem is if Server is not Working , it delays and the UI wents to ANR 
              if(  sendToWebservice(String_to_send)=="fromWebservice") {
                Toast.makeText(context, "Connected", 500).show();

              }
             else {
                Toast.makeText(context, "Not Connected,Try again ", 500).show();
                finish();
            }
     } 
    }, 5000); 

Additional Info: I am using jax.ws to create webservice & ksoap api in Android. Thanks in Advance.

Edit

if(  sendToWebservice(String_to_send).equalIgnorecase("fromWebservice") instead of ==

I missed to put this while framing it into syntax here..!!

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Pradeepraj
  • 423
  • 1
  • 8
  • 15

1 Answers1

2

First of All, This condition should be,

if(sendToWebservice(String_to_send).equals("fromWebservice")) 

Now for ANR,

You can put response timeout in your HTTP request so, if there is time delay then you get timeout response from server, Also if possible display some progress dialog when any webservice call has made in UI thread and your web service call in other worker thread.

user370305
  • 108,599
  • 23
  • 164
  • 151