2011-03-07 42 views

回答

4

您使用擴展AsynTask的類... 請參閱此link

在你的doInBackground()裏面調用你的插入方法。

更多的解釋:

烏爾活動中創建一個內部類InsertTask,如:

private class InsertTask extends AsyncTask<String, Void, Boolean> { 

     @Override 
     protected void onPreExecute() { 
      super.onPreExecute(); 
     } 

     @Override 
     protected Boolean doInBackground(String... params) { 

      Boolean success = false; 

      try { 
       //place insert code here 
       success = true; 
      } catch (Exception e) { 
       if(e.getMessage()!=null) 
        e.printStackTrace(); 
      } 
      return success; 
     } 

     @Override 
     protected void onPostExecute(Boolean success) { 
      super.onPostExecute(success); 
     } 
    } 

在我們共同的onCreate()給:

new InsertTask.execute(); //this calls the doInBackground method of InsertTask 

通過這樣做,當烏爾活動被調用,doInBackground()內部寫入的內容將通過插入ur值來運行。

+0

thanx很多它適用於我的應用程序...真棒.. – 2011-03-07 11:34:05

+0

總是歡迎.. – Mathew 2011-03-07 11:41:48

相關問題