Skip to content Skip to sidebar Skip to footer

Windowleaked From Dialog

I'm having a typical WindowLeaked exception 03-03 21:03:26.441: ERROR/WindowManager(631): Activity com.myapp.Player has leaked window com.android.internal.policy.impl.PhoneWin

Solution 1:

Maybe you could try to show your Toast through runOnUiThread ?

Something like:

@OverridepublicbooleanonError(MediaPlayer arg0, int arg1, int arg2) {
       Player.this.runOnUiThread(newRunnable() {
           voidrun() {
               Toast.makeText(Player.this, "Sorry, unable to play this video", Toast.LENGTH_LONG).show();
               progressDialog.dismiss();
               if (mToken != null) {
                    MusicUtils.unbindFromService(mToken);
                }
                finish();
           }
        );
        returnfalse;
    }

EDIT:

Here is more...below is the code (in Froyo) for the VideoView.

Seems like the error comes from the AlertDialog.Builder... but based on your code, it should not even get there since the error should be handled higher when mOnErrorListener is not null...

Can you check whether your error handler is being called ? Maybe try to not call finish() there ?

private MediaPlayer.OnErrorListener mErrorListener =
        new MediaPlayer.OnErrorListener() {
        public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
            Log.d(TAG, "Error: " + framework_err + "," + impl_err);
            mCurrentState = STATE_ERROR;
            mTargetState = STATE_ERROR;
            if (mMediaController != null) {
                mMediaController.hide();
            }

            /* If an error handler has been supplied, use it and finish. */if (mOnErrorListener != null) {
                if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err)) {
                    returntrue;
                }
            }

            /* Otherwise, pop up an error dialog so the user knows that
             * something bad has happened. Only try and pop up the dialog
             * if we're attached to a window. When we're going away and no
             * longer have a window, don't bother showing the user an error.
             */if (getWindowToken() != null) {
                Resources r = mContext.getResources();
                int messageId;

                if (framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
                    messageId = com.android.internal.R.string.VideoView_error_text_invalid_progressive_playback;
                } else {
                    messageId = com.android.internal.R.string.VideoView_error_text_unknown;
                }

                new AlertDialog.Builder(mContext)
                        .setTitle(com.android.internal.R.string.VideoView_error_title)
                        .setMessage(messageId)
                        .setPositiveButton(com.android.internal.R.string.VideoView_error_button,
                                new DialogInterface.OnClickListener() {
                                    publicvoidonClick(DialogInterface dialog, int whichButton) {
                                        /* If we get here, there is no onError listener, so
                                         * at least inform them that the video is over.
                                         */if (mOnCompletionListener != null) {
                                            mOnCompletionListener.onCompletion(mMediaPlayer);
                                        }
                                    }
                                })
                        .setCancelable(false)
                        .show();
            }
            returntrue;
        }
    };

MORE EDIT:

Change the onError handler to return true;

Then the "default" error handler will not try to build this AlertDialog

Solution 2:

The Error listener event is probably not coming back to you on the UI (looper) thread. You need to post an event to a handler (registered on the UI thread) have the handler show the Toast and dismiss the progress dialog.

Post a Comment for "Windowleaked From Dialog"