我正在編寫一個具有介紹視頻的android應用程序,該應用程序是首先播放的mp4文件。用戶可以觸摸屏幕跳過它。「活動泄露了原本添加的窗口......」由未能加載的視頻引起
當我嘗試在android模擬器上運行我的應用程序時,我得到一個「活動泄漏了窗口..最初添加的」窗口異常。在stackoverflow上有一個關於它的大帖子,說如果我的東西試圖在完成後啓動一個對話框。也許在我的情況下,玩家正在嘗試啓動一個對話框,說明播放器不支持我的視頻格式。
好..所以我只是想要跳過視頻。沒有它拋出一個錯誤和例外。
這是我的介紹活動:
package com.tuxin.findasmile;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
//import android.view.Menu;
import android.view.MotionEvent;
import android.widget.VideoView;
public class IntroActivity extends Activity {
private VideoView video;
private boolean isMenuStarted=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
video = (VideoView) findViewById(R.id.videoView1);
video.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
Intent menu = new Intent(IntroActivity.this,MenuActivity.class);
startActivity(menu);
finish();
return false;
}
});
video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
if (!isMenuStarted) {
isMenuStarted=true;
Intent menu = new Intent(IntroActivity.this,MenuActivity.class);
startActivity(menu);
finish();
}
}
});
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.seaofbuttons);
video.setVideoURI(videoUri);
video.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (video.isPlaying()) {
video.stopPlayback();
}
if (!isMenuStarted) {
isMenuStarted=true;
Intent menu = new Intent(IntroActivity.this,MenuActivity.class);
startActivity(menu);
finish();
}
return false;
}
}
我知道,仿真器不支持視頻。但我想支持手機不支持這種視頻格式的情況。我不希望拋出異常。
04-01 16:32:38.675: E/WindowManager(533): Activity com.tuxin.findasmile.IntroActivity has leaked window [email protected] that was originally added here
04-01 16:32:38.675: E/WindowManager(533): android.view.WindowLeaked: Activity com.tuxin.findasmile.IntroActivity has leaked window [email protected] that was originally added here
04-01 16:32:38.675: E/WindowManager(533): at android.view.ViewRoot.<init>(ViewRoot.java:258)
04-01 16:32:38.675: E/WindowManager(533): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-01 16:32:38.675: E/WindowManager(533): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-01 16:32:38.675: E/WindowManager(533): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-01 16:32:38.675: E/WindowManager(533): at android.app.Dialog.show(Dialog.java:241)
04-01 16:32:38.675: E/WindowManager(533): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
04-01 16:32:38.675: E/WindowManager(533): at android.widget.VideoView$4.onError(VideoView.java:386)
04-01 16:32:38.675: E/WindowManager(533): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1341)
04-01 16:32:38.675: E/WindowManager(533): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 16:32:38.675: E/WindowManager(533): at android.os.Looper.loop(Looper.java:123)
04-01 16:32:38.675: E/WindowManager(533): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-01 16:32:38.675: E/WindowManager(533): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 16:32:38.675: E/WindowManager(533): at java.lang.reflect.Method.invoke(Method.java:507)
04-01 16:32:38.675: E/WindowManager(533): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-01 16:32:38.675: E/WindowManager(533): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-01 16:32:38.675: E/WindowManager(533): at dalvik.system.NativeStart.main(Native Method)
謝謝!我忙着試圖弄清楚我的進度對話框是如何泄漏的,原來是錯誤處理程序。我從onError()調用finish(),所以也沒有看到嘗試的錯誤對話框。 –