2013-04-24 69 views
0

我有,如果我做得很好这是工作每半小时定时采取行动的一些KSOAP Web服务。其中一人送全表行到SQL Server,它原来我0或1,取决于正确发送。如果它返回1,它必须从sqlite中删除所有行。 Altough它返回1,它不进入if语句并不起作用delete命令。 我不知道我的计时器和线程是这个正确的方法,我怎样才能正确地做到这一点?我在哪里可以把IF语句的工作?

验证码:

try 
     { 
      final Timer V_Timer; 
      final Handler V_Handler; 
      V_Timer = new Timer(); 
      V_Handler = new Handler(Looper.getMainLooper()); 
      V_Timer.scheduleAtFixedRate(new TimerTask() 
      { 
       public void run() 
       {     
        V_Handler.post(new Runnable() 
       { 
       public void run() 
       { 
       //for status update// 
        if(isConnected()){     
        Thread networkThread = new Thread() { 
        @Override 
        public void run() { 

         try { 
          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_STATUS); 

          request.addProperty("MH_ID",hardwareID); 
          request.addProperty("Latitude",V_Latitude); 
          request.addProperty("Longitude",V_Longitude); 


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

         HttpTransportSE ht = new HttpTransportSE(URL); 
         ht.call(SOAP_ACTION_STATUS, envelope); 
         final SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
         final String str_ = response.toString(); 
         //final String str = response.toString()+"\n"+ V_Latitude +"\n"+V_Longitude; 

         runOnUiThread (new Runnable(){ 
        public void run() { 
         Toast.makeText(MainActivity.this, str_, Toast.LENGTH_LONG).show(); 
        } 
         }); 
         } 
         catch (Exception e) { 
          e.printStackTrace(); 
         } 
         } 
        }; 
        networkThread.start(); 

        //Insert Bulk// 

        if(isConnected()){     
          Thread networkThread2 = new Thread() { 
          @Override 
          public void run() { 
           str = "0"; 

           try { 
            StringBuilder bulk = GetTotalRecord(); 
            bulkinsert = bulk.toString(); 
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_BULK); 

            request.addProperty("Insert_Bulk",bulkinsert);                  

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

           HttpTransportSE ht = new HttpTransportSE(URL); 
           ht.call(SOAP_ACTION_BULK, envelope); 
           final SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
           str = response.toString(); 


           runOnUiThread (new Runnable(){ 
          public void run() { 
           // Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show(); 
           /////delete sqlite table///// 

           Log.d("str", str); 

            if (str=="1") 
           { 
            try { 
              dbobject.delete(SQLiteDB.TABLE_NAME_S, null, null); 
              Toast.makeText(MainActivity.this, "All Answers sent", Toast.LENGTH_LONG).show() ; 
             } catch (Exception e) { 
              // TODO Auto-generated catch block 
              Toast.makeText(MainActivity.this, "Error: Answers could not send \n "+e.toString(), Toast.LENGTH_LONG).show(); 
              e.printStackTrace(); 
             } 
            finally{ 
             sqlitedb.close(); 
            } 
           } 

           /////delete sqlite table///// 

          } 
           }); 
           } 
           catch (Exception e) { 
            e.printStackTrace(); 
           } 
           } 
          }; 
          networkThread2.start(); 


        //Insert Bulk end//               

       } 
       } 
       }}); 
       } 
      },10000, 1000*60*30);   
        }  
     catch(Exception ex) 
     {  

     } 

回答

0
if (str=="1") 

你不能在Java比较String对象这种方式。

您应该使用equalsTo()或转换strint

例如:

if (str.equalsTo("1")) { 
} 

int strInt = Integer.parseInt(str) 

if (strInt == 1) { 
} 
+0

感谢@blackbelt,它的工作以及.. – 2013-04-24 12:15:27

+0

欢迎您 – Blackbelt 2013-04-24 12:15:46