我有一個典型WindowLeaked例外WindowLeaked從對話框
03-03 21:03:26.441:ERROR /窗口管理(631):活動 com.myapp.Player已泄漏窗口 com.android .internal.policy.impl.PhoneWindow $ DecorView @ 45136c38 最初在這裏添加03-03 21:03:26.441: 錯誤/ WindowManager(631):android.view.WindowLeaked:活動 com.myapp.Player泄漏窗口 [email protected] 最初是在這裏添加的03-03 21:03:26.441: 錯誤/ WindowManager(631):在 android.view.ViewRoot。(ViewRoot.java:247)03-03 21:03:26.441: 錯誤/ WindowManager(631):在 android.view.WindowManagerImpl.addView( WindowManagerImpl.java:148) 03-03 21:03:26.441:ERROR/WindowManager(631):at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 03-03 21:03:26.441:ERROR/WindowManager(631):at android.view.Window $ LocalWindowManager.addView(Window.java:424)03-03 21:03:26.441:ERROR/WindowManager(631):at android.app.Dialog.show (Dialog.java:241)03-03 21:03:26.441: 錯誤/ WindowManager(631):at android.app.AlertDialog $ Builder.show(AlertDialog.java:802)03-03 21:03:26.441:ERROR/WindowManager(631):at android.widget.VideoView $ 4.onError(VideoView.java:387)03-03 21:03:26.441:ERROR/WindowManager(631):at android.media.MediaPlayer $ EventHandler.handleMessage(MediaPlayer.java:1264) 03-03 21:03:26.441:ERROR/WindowManager(631):at android.os.Handler.dispatchMessage(Handler.java:99)03 -03 錯誤/ WindowManager(631):在 android.os.Looper.loop android.app.ActivityThread.main(ActivityThread.java:4627)03-03 21:03:26.441:ERROR/WindowManager(631):at java.lang.reflect.Method.invokeNative(Native Method)03 -03 錯誤/ WindowManager(631):在 錯誤/ WindowManager(631)錯誤/ WindowManager(631):0335 21:03:26.441: :at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 03-03 21:03:26.441:ERROR/WindowManager(631):at com.android.internal.os。 ZygoteInit.main(ZygoteInit.java:626)03-03 21:03:26.441:ERROR /窗口管理器(631):在 dalvik.system.NativeStart.main(本機方法)
的答案都不對到目前爲止,我讀過的書似乎解決了它。下面是代碼:
mVideoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
Toast.makeText(Player.this, "Sorry, unable to play this video", Toast.LENGTH_LONG).show();
progressDialog.dismiss();
if (mToken != null) {
MusicUtils.unbindFromService(mToken);
}
finish();
return false;
}
});
我留下了唯一的猜測是,烤麪包緊緊依靠活動,但一切我讀似乎在說祝酒無所謂。我甚至嘗試過使用getBaseContext(),然後嘗試在finish()之後放置toast以查看它是否可行。我完全沒有想法,所以任何幫助都會很棒。
更新:這裏是更多的代碼
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
extras = getIntent().getExtras();
media_url = extras.getString("media_url");
setContentView(R.layout.video_player);
//Start progress dialog so user knows something is going on
progressDialog = ProgressDialog.show(this, "", "Loading...", true);
mVideoView = (VideoView) findViewById(R.id.surface_view);
runOnUiThread(new Runnable(){
public void run() {
playVideo();
}
});
}
private void playVideo() {
try {
if (media_url == null || media_url.length() == 0) {
progressDialog.dismiss();
Toast.makeText(VideoPlayer.this, "File URL/media_url is empty",
Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (media_url.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = media_url;
mVideoView.setVideoURI(Uri.parse(media_url));
ctlr=new MediaController(VideoPlayer.this);
ctlr.setMediaPlayer(mVideoView);
mVideoView.setMediaController(ctlr);
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
progressDialog.dismiss();
mVideoView.start();
}
});
mVideoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
Toast.makeText(VideoPlayer.this, "Sorry, unable to play this video",
Toast.LENGTH_LONG).show();
progressDialog.dismiss();
if (mToken != null) {
MusicUtils.unbindFromService(mToken);
}
finish();
return false;
}
});
}
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
if (mVideoView != null) {
mVideoView.stopPlayback();
}
finish();
}
}
private void startPlayback() {
if(mService == null)
return;
Intent intent = getIntent();
String filename = "";
Uri uri = intent.getData();
if (uri != null && uri.toString().length() > 0) {
String scheme = uri.getScheme();
if ("file".equals(scheme)) {
filename = uri.getPath();
} else {
filename = uri.toString();
}
try {
mService.stop();
mService.openFileAsync(filename);
mService.play();
setIntent(new Intent());
} catch (Exception ex) {
Log.e(tag, "couldn't start playback: " + ex);
}
}
}
private ServiceConnection osc = new ServiceConnection() {
public void onServiceConnected(ComponentName classname, IBinder obj) {
mService = IMediaPlaybackService.Stub.asInterface(obj);
startPlayback();
}
public void onServiceDisconnected(ComponentName classname) {
mService = null;
}
};
錯誤發生的時候它是一個視頻類型的設備不能發揮
那是什麼'progressDialog.dismiss( )'在那裏?我認爲我們需要更多代碼才能查明問題。 – dmon 2012-03-04 03:53:09
@dmon它只是擺脫加載progressDialog。即使我完全刪除了activity中的progressDialog,我仍然得到錯誤,所以這不是問題 – Cameron 2012-03-05 23:36:52
@dmon我添加了更多的代碼 – Cameron 2012-03-08 00:24:14