2010-11-19 80 views
1

在我的應用程序中,我已經實現了按下硬件音量鍵顯示當前音量的Toast。大部分時間事情順利。然而長按音量鍵可以成功地使我的應用程序崩潰。上碰撞所產生的日誌如下:Toast崩潰應用程序

.... 
11-19 06:43:22.114 I/NotificationService(2783): enqueueToast pkg=com.FunTime.android [email protected] duration=0 
11-19 06:43:22.119 V/WindowManager(2783): Delivering key 25 to Window{47f6a930 com.FunTime.android/com.FunTime.android.map.MapActivity paused=false} 
11-19 06:43:22.164 I/NotificationService(2783): enqueueToast pkg=com.FunTime.android [email protected] duration=0 
11-19 06:43:22.169 V/WindowManager(2783): Delivering key 25 to Window{47f6a930 com.FunTime.android/com.FunTime.android.map.MapActivity paused=false} 
11-19 06:43:22.209 I/NotificationService(2783): enqueueToast pkg=com.FunTime.android [email protected] duration=0 

...many such notifications... 

11-19 06:43:22.244 E/SurfaceFlinger(2783): createSurface() failed, generateId = -12 
11-19 06:43:22.244 W/WindowManager(2783): OutOfResourcesException creating surface 
11-19 06:43:22.244 I/WindowManager(2783): Out of memory for surface! Looking for leaks... 
11-19 06:43:22.244 W/WindowManager(2783): No leaked surfaces; killing applicatons! 
11-19 06:43:22.244 W/ActivityManager(2783): Killing processes for memory at adjustment 0 
11-19 06:43:22.244 W/ActivityManager(2783): Killing for memory: ProcessRecord{47dd75c8 3246:com.FunTime.android/10079} (adj 0) 
11-19 06:43:22.244 I/Process (2783): Sending signal. PID: 3246 SIG: 9 
11-19 06:43:22.244 W/WindowManager(2783): Looks like we have reclaimed some memory, clearing surface for retry. 
11-19 06:43:22.244 W/WindowManager(2783): Due to memory failure, waiting a bit for next layout 

我按照該方法: 我有一個烤麪包的對象和用於每個鍵按壓事件檢測的I膨脹的圖,設定內的視圖的元件,將其設置爲烤麪包然後顯示敬酒。

任何想法是什麼問題?

遲來編輯

在基本活動類從我的所有活動繼承:

public boolean onKeyDown(int keyCode, KeyEvent event) 
{ 
    if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN) 
    { 
     myAudioManager.getInstance().onVolumeDown(); 
       myAudioManager.getInstance().showVolumeAdjustment(myAudioManager.getInstance().getVolume()); 
     return true; 
    } 
    else if(keyCode==KeyEvent.KEYCODE_VOLUME_UP) 
    { 
     myAudioManager.getInstance().onVolumeUp(); 
      myAudioManager.getInstance().showVolumeAdjustment(myAudioManager.getInstance().getVolume()); 
     return true; 
     } 
    return super.onKeyDown(keyCode, event); 
} 

在myAudioManager

public void showVolumeAdjustment(final int adjustment) 
{ 
     volumeToast.setDuration(Toast.LENGTH_SHORT); 
     volumeToast.setView(getVolumeProgressBarView(adjustment)); 
     volumeToast.setGravity(Gravity.TOP,0,0); 
     volumeToast.show(); 
} 

private View getVolumeProgressBarView(int adjustment) 
{ 
     LayoutInflater inflater = (LayoutInflater) myApplication.getInstance().getApplicationContext() 
             .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     toastView= inflater.inflate(R.layout.volume_toast, null); 
     ProgressBar pb =(ProgressBar)toastView.findViewById(R.id.level); 
     pb.setMax(MAX_VOICE_VOLUME_ENGINE); 
     pb.setProgress(adjustment); 
     return toastView; 
} 
+0

您應該發佈顯示您如何設置按鍵事件處理程序的代碼,以及如何顯示敬酒。沒有看到你實際做了什麼,很難說你做錯了什麼。 – Nailuj 2010-11-19 08:20:27

回答

2

您做出太多的祝酒詞,並填寫了內存。

嘗試放一個計時器,或者用來限制生成的吐司數量。