2017-01-11 1 views
0

나는 AsyncTask에 WindowLeaks가 있는데 어떻게 처리해야할지 모르겠다. onPostExecutedismiss()을 넣으려고 했는데도 여전히 같은 문제가 발생했다.AsyncTask의 WindowLeaked

protected void onPreExecute() { 
    if(this.showLoadingMessage) { 
     this.progressDialog = new ProgressDialog(this.context); 
     this.progressDialog.setMessage(this.loadingMessage); 
     this.progressDialog.show(); 
     this.progressDialog.setCancelable(false); 
    } 
    super.onPreExecute(); 
} 
protected void onPostExecute(String result) { 
    if(this.showLoadingMessage && this.progressDialog.isShowing()) { 
     this.progressDialog.dismiss(); 
    } 

    result = result.trim(); 
    if(this.asyncResponse != null) { 
     this.asyncResponse.processFinish(result); 
    } 

    if(this.exception != null) { 
     if(this.exceptionHandler != null) { 
      this.exceptionHandler.handleException(this.exception); 
     } 

     if(this.eachExceptionsHandler != null) { 
      Log.d(this.LOG, "" + this.exception.getClass().getSimpleName()); 
      if(this.exception instanceof MalformedURLException) { 
       this.eachExceptionsHandler.handleMalformedURLException((MalformedURLException)this.exception); 
      } else if(this.exception instanceof ProtocolException) { 
       this.eachExceptionsHandler.handleProtocolException((ProtocolException)this.exception); 
      } else if(this.exception instanceof UnsupportedEncodingException) { 
       this.eachExceptionsHandler.handleUnsupportedEncodingException((UnsupportedEncodingException)this.exception); 
      } else if(this.exception instanceof IOException) { 
       this.eachExceptionsHandler.handleIOException((IOException)this.exception); 
      } 
     } 
    } 

} 

이 코드가 작동하면이 누출이 발생합니다.

         HashMap postNotification = new HashMap(); 

            postNotification.put("txtOwner", tvRenter.getText().toString()); 

            AsyncClass taskCount = new AsyncClass(ownerAccept.this, postNotification, new AsyncResponse() { 
             @Override 
             public void processFinish(String s) { 
              if(s.contains("success")){ 
               HashMap postNotif = new HashMap(); 

               postNotif.put("txtOwner", tvRenter.getText().toString()); 

               AsyncClass taskAdd = new AsyncClass(ownerAccept.this, postNotif, new AsyncResponse() { 
                @Override 
                public void processFinish(String s) { 
                 if(s.contains("success")){ 
                  Log.d(TAG, s); 
                  Intent in = new Intent(ownerAccept.this, RenterTabs.class); 
                  startActivity(in); 
                  finish(); 
                 } 
                } 
               }); 
                taskAdd.execute("http://carkila.esy.es/carkila/notificationAccept.php"); 
              } else { 
               Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show(); 
              } 
             } 
            }); 
            taskCount.execute("http://carkila.esy.es/carkila/notificationCount.php"); 
           } 
          }) 
          .setNegativeButton("No", new DialogInterface.OnClickListener() { 
           @Override 
           public void onClick(DialogInterface dialog, int which) { 
            dialog.cancel(); 
           } 
          }); 
        AlertDialog alert = a_accept.create(); 
        alert.setTitle("Accept"); 
        alert.show(); 
+0

'context'는 어디에서 왔습니까? 'context'를 제공하는'Activity'를 끝내고 있다면 당신은 누출로 끝날 것입니다. – Pztar

+0

'LogCat'을 게시 할 수 있습니까? 이전 작업을 해지하고 작업을 끝내지 않고 새로운 '대화 상자'를 표시하기 때문에 문제를 일으키는 것으로 보이는 첫 번째 콜백에서 새 작업을 실행하는 것처럼 보입니다. – Pztar

답변

0

언제 이러한 누출이 있습니까? AsyncTask를 시작한 활동 (또는 단편)이 파손되면 이러한 누수가 발생합니다.

+0

누수가있는 활동을 추가했습니다. – JosephG

+0

AsyncTasks를 IntentServices로 마이그레이션하면이 문제를 피할 수 있습니다. AsyncTask는 메모리 문제 또는 WindowLeaks를 얻을 다른 이유로 파괴 된 경우 활동 또는 조각을 사용합니다. 안드로이드의 서비스 가이드 https://developer.android.com/guide/components/services.html을 읽어 보시기 바랍니다. 그것은 더 많은 코드를 작성하지만 결국 보람이 있습니다. –

+0

+ JosephG 전체 스택 추적을 표시 할 수 있습니까? 문제는 대화 상자를 표시하는 방식 일 수도 있습니다. –