Note that there are some explanatory texts on larger screens.

plurals
  1. POToast crashes application
    text
    copied!<p>In my application I've implemented such that pressing the hardware volume keys displays a Toast with the current volume. Things go well most of the times. However long presses of the volume keys do succeed in crashing my application. The Log generated on crash is the following :</p> <pre><code>.... 11-19 06:43:22.114 I/NotificationService( 2783): enqueueToast pkg=com.FunTime.android callback=android.app.ITransientNotification$Stub$Proxy@47b679a8 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 callback=android.app.ITransientNotification$Stub$Proxy@47a980b0 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 callback=android.app.ITransientNotification$Stub$Proxy@47b4d270 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 </code></pre> <p>The approach I follow: I have a toast Object and for every key press event detected I inflate a view ,set the view elements within, set it to the toast and then show the toast.</p> <p>Any idea what is going wrong ?</p> <p>Lated Edited </p> <p>In the base activity class from which all my activities inherit:</p> <pre><code>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); } </code></pre> <p>In myAudioManager </p> <pre><code> 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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload