2015-11-09 100 views
0

如何显示警告消息,如果我无法与url进行握手,则显示警报消息 我在下面的字段中传递URL,如果我无法见面该网址(404网址为gatway错误)。我需要diplay一个警告框如果无法访问服务器(url)

忘记进入onPOST等EXCUTE,它会停留在做后台只,但如何显示在待办事项警报的背景 - 我的代码

private class CheckTypesTask extends AsyncTask<Void, Void, Void> { 
     ProgressDialog asyncDialog = new ProgressDialog(MainActivity.this); 


     @Override 
     protected void onPreExecute() { 
      // set message of the dialog 
      asyncDialog.setMessage("Please Wait..."); 
      // show dialog 
      asyncDialog.setCancelable(false); 
      asyncDialog.show(); 
      super.onPreExecute(); 
     } 
      @Override 
     protected Void doInBackground(Void... arg0) { 


      try { 

       userna = user.getText().toString(); 
       passwd = pass.getText().toString(); 

       String serial = Build.SERIAL; 
       Log.e("login method", userna + " " + passwd + "" + serial); 
       ; 
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
       PropertyInfo propInfo1 = new PropertyInfo(); 
       propInfo1.setName("conidential"); 
       propInfo1.setValue(user.getText().toString().trim()); 
       propInfo1.setType(String.class); 
       request.addProperty(propInfo1); 

       PropertyInfo propInfo2 = new PropertyInfo(); 
       propInfo2.setName("conidential"); 
       propInfo2.setValue(pass.getText().toString().trim()); 
       propInfo2.setType(String.class); 
       request.addProperty(propInfo2); 

       PropertyInfo propInfo3 = new PropertyInfo(); 
       propInfo3.setName("DeviceId"); 
       propInfo3.setValue(serial); 
       propInfo3.setType(String.class); 
       request.addProperty(propInfo3); 

       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
         SoapEnvelope.VER11); 
       envelope.dotNet = true; 

       envelope.setOutputSoapObject(request); 
       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
       androidHttpTransport.debug = true; 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       // Object response = (Object)envelope.getResponse(); 

       // SoapPrimitive response = 
       // (SoapPrimitive)envelope.getResponse(); 

       SoapObject response = (SoapObject) envelope.getResponse(); 

       String status = response.getProperty("Status").toString(); 

       if (status.equals("1")) { 

        storename = response.getProperty("StoreName").toString(); 
       } 

       Log.i("myApp", status.toString() + "Storename:" + storename); 
       typeStatus = status.toString(); 

      } catch (Exception e) { 
       e.printStackTrace(); 
       Log.e("exception at doin", e.toString()); 
      } 
      return null; 
     } 
       @Override 
     protected void onPostExecute(Void result) { 
      // hide the dialog 
      asyncDialog.dismiss(); 
      try { 
       if (typeStatus.equals("1")) { 
       ///////////doing my stuff 
      super.onPostExecute(result); 
      } 
     } 
     } 
     } 
+0

发布错误堆栈跟踪。 –

回答

0

你可尝试将runOnUIthread放入doInBackground(Void ... arg0){

try { 
runOnUiThread(new Runnable() { 

        @Override 
        public void run() { 
         Toast.makeText(context, text, duration).show(); 
        } 
       }); 
       Thread.sleep(300); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      }