2014-04-28 4 views
0

나는 그것을 클릭 할 때 일부 데이터를 클라우드로 보내는 메뉴 버튼이 있습니다. 데이터를 보내는 동안 진행률 대화 상자가 표시됩니다. 모든 것들이 헤엄 쳐서 멋지게 보이고 원하는만큼 버튼을 누를 수 있으며 데이터가 클라우드로 제대로 보내집니다. 내가 활동을 종료 갈 때 는하지만 오류가 창 누수가 있다고 말하는 얻을 :엎드려서 전화 걸기 후에도 진행 대화 상자가 누설 된 창 오류

com.android.internal.policy.impl.PhoneWindow$DecorView{4321fd38 V.E..... R......D 0,0-1026,288} that was originally added here 

의 I 내 진행 대화 상자를 만족할 줄 모르는 경우 "여기"를 참조한다.

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
progressDialog = ProgressDialog.show(CruiseDetailRollCallActivity.this, "", "Loading...", true);//set up & show progress dialog 

switch(item.getItemId()){ 
case R.id.menu_roll_call_opt_in: 
    //saveing something into Parse -- (a database online, check Parse.com if you want more info, but just treat this like I am saving something into the cloud) 
    currentUser.put("somethingBoolean", false); 
    currentUser.saveInBackground(new SaveCallback(){ 

    @Override 
    public void done(ParseException e) { //once data has been put into the cloud 
     progressDialog.dismiss();//dismiss the dialog 
     supportInvalidateOptionsMenu();//refreshes the options menu 
    } 
    }); 

    return true; 

default: 
    return super.onOptionsItemSelected(item); 
} 
} 

나는이 내 응용 프로그램 충돌하지만 단순히 오류를 표시하지 않습니다 언급해야 :

여기 내 코드입니다. 왜 그런 일이 일어나고 있는지 전혀 모른다. 나는 그것을 무시해서는 안된다.

수정 : 내 실수를 발견했습니다. 작업 표시 줄에 다시 타격을 가하고 진행률 대화 상자가 생성되지만 완료 코드 내부에서만 해제되었으므로 해고하지 않았기 때문에 작업이 실패했기 때문에 실패했습니다.

+0

당신이'해고 중지시'의 발전 Dialog'()해야 보이는

case R.id.menu_roll_call_opt_in: //saveing something into Parse -- (a database online, check Parse.com if you want more info, but just treat this like I am saving something into the cloud) currentUser.put("somethingBoolean", false); currentUser.saveInBackground(new SaveCallback(){ @Override public void done(ParseException e) { //once data has been put into the cloud progressDialog.dismiss();//dismiss the dialog supportInvalidateOptionsMenu();//refreshes the options menu } }); return true; 

progressDialog = ProgressDialog.show(CruiseDetailRollCallActivity.this, "", "Loading...", true);//set up & show progress dialog 

을 움직였다.' –

+0

를 참조 @SimplePlan 내 대답은 아래에 나와 있습니다. onStop()은 killable이며 운영체제가 결정한 것에 따라 onStop()이 결코 실행되지 않을 수도 있습니다. – mttdbrd

답변

1

작업 표시 줄에 다시 나타 났기 때문에 작업이 실패했기 때문에 작업 표시 줄에 오류가있었습니다. 진행률 대화 상자는 만들어졌지만 완료 코드 내부에서만 해제되었으므로 닫히지 않았습니다.

나는 그래서이

case R.id.menu_roll_call_opt_in: 
progressDialog = ProgressDialog.show(CruiseDetailRollCallActivity.this, "", "Loading...", true);//set up & show progress dialog 
//saveing something into Parse -- (a database online, check Parse.com if you want more info, but just treat this like I am saving something into the cloud) 
currentUser.put("somethingBoolean", false); 
currentUser.saveInBackground(new SaveCallback(){ 

@Override 
public void done(ParseException e) { //once data has been put into the cloud 
    progressDialog.dismiss();//dismiss the dialog 
    supportInvalidateOptionsMenu();//refreshes the options menu 
} 
}); 

return true; 
같은 것을
1

내 생각에 CruiseDetailRollCallActivitycurrentUser.saveInBackground(new SaveCallback()...에 전달하면 currentUser 개체로 활동이 누출됩니다. 방금 작성한 SaveCallback 클래스에는 활동에 대한 강력한 참조가 있습니다. 메서드를 종료하더라도 가비지 수집되지 않습니다. WeakReference을 사용해야하며 그런 다음 가비지 수집 될 수 있습니다. 그런 다음

WeakReference<CruiseDetailRollCallActivity> weakRef = new WeakReference<CruiseDetailRollCallActivity>(CruiseDetailRollCallActivity.this) 

의해서 ProgressDialog 생성자에 weakRef을 통과 : 당신은 안드로이드의 문맥 주위에 전달하는 때마다

progressDialog = ProgressDialog.show(weakRef.get(), "", "Loading...", true); 

, 그것은 쓰레기 수집 할 수 있도록 당신이 WeakReference를 필요한 경우 확인 . 전체 응용 프로그램을 쉽게 누출시킬 수 있습니다.

+0

내 응용 프로그램에서 비슷한 코드를 실행하고 오류가 발생하지 않기 때문에 완전히 이해하지 못합니다. 그러나 코드가 작동했습니다. – Sree

+0

그런 다음 다른 모든 코드를 수정해야합니다. 기기에서 메모리 누수가 발생했습니다. 사람들은 앱을 사지 않을 것입니다! :) – mttdbrd

+1

이 문제에 대한 블로그 게시물을 작성했습니다. 특히 Android로 작업하는 경우 WeakReferences 및 가비지 수집에 대해 배우는 것이 좋습니다. 시스템은 기본적으로 메모리 누수를 일으키기 위해 설계되었습니다. 그리고 그것은 지난 며칠 사이에 너무 많이 올라오고있는 것처럼 보입니다. 자세한 설명은 http : // tmblr에서 읽을 수 있습니다.공동/ZSJA4p13azutu – mttdbrd