2012-03-09 43 views
0

我有一個在AsyncTask中運行doInBackground中的一些方法,它調用webservices並將數量的記錄插入數據庫,在同一用戶上單擊其他屏幕然後outOfmemoryError即將來臨我想暫時停止後臺線程直到屏幕加載,然後線程不得不從它停止,以便內存釋放。任何人都可以告訴我如何實現這一目標。 在此先感謝。outofmemoryerror在android

+0

該問題有兩個階段。 – 2012-03-09 05:46:33

+0

我不能低估你在問什麼 – user1108995 2012-03-09 05:52:11

+0

我認爲你應該使用服務這一點。 – Nitin 2012-03-09 06:34:57

回答

0

的的AsyncTask只能執行一次(如果第二試圖執行一個異常將被拋出。)..所以暫停和恢復..我認爲你應該使用一個backgroundthread,而不是...

0
//decleration 
ProgressDialog dialog; 

//onCreate 
dialog = new ProgressDialog(ActivityName.this); 

public class BackGroundTask extends AsyncTask<String, String, String> { 

     @Override 
     protected String doInBackground(String... params) { 
      // TODO Auto-generated method stub 

      //perform background task 

      return null; 
     } 

     @Override 
     protected void onPreExecute() { 
      // TODO Auto-generated method stub 
      super.onPreExecute(); 
      dialog.setMessage("Please wait....."); 
      dialog.setIndeterminate(true); 
      dialog.setCancelable(false); 
      dialog.show(); 

     } 

     @Override 
     protected void onPostExecute(String sResponse) { 

       if (dialog.isShowing()) 
         { 
        dialog.dismiss(); 

         } 

    }