我想在Android应用程序的开头播放一部电影。所以我使用此代码但它会生成此错误:
android.view.WindowLeaked:MainActivity泄露了窗口com.android.internal.policy
public class MainActivity extends AppCompatActivity {
private static int TIME_OUT = 8000;
String SrcPath = "android.resource://com.appdev.loicomelectronique/debut";
VideoView video;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);
setContentView(R.layout.activity_main);
video = (VideoView)findViewById(R.id.videoView);
video.setVideoURI(Uri.parse(this.SrcPath));
video.requestFocus();
video.start();
new Handler().postDelayed(new Runnable()
{
public void run()
{
Intent localIntent = new Intent(MainActivity.this, MainActivityLoi.class);
startActivity(localIntent);
//MainActivity.this.finish();
}
}, TIME_OUT);
}
}
请问我该怎么办呢。我在网上找到的只是显示一个Dialog,但在我的情况下,它是一个视频。
由于
答案 0 :(得分:1)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);
setContentView(R.layout.activity_main);
video = (VideoView)findViewById(R.id.videoView);
video.setVideoURI(Uri.parse(this.SrcPath));
video.requestFocus();
video.start();
mHandler=new Handler();
mRunable=new Runable()
{
public void run()
{
Intent localIntent = new Intent(MainActivity.this, MainActivityLoi.class);
startActivity(localIntent);
//MainActivity.this.finish();
}
};
mhandler.postDelayed(mRunnable,TIME_OUT);
}
@Override
protected void onStop() {
if(mHandler!=null){
if(mHandler!=null){
mHandler.removeCallbacks(mRunnable);
}
mHandler==null;
}
super.onStop();
}
答案 1 :(得分:0)
这是我的layout.xml文件
<div class="menu">
<div class="menu_content">
<a href="#" class="menuBtn">Start</a>
</div>
</div>
我没有指定视频的尺寸,只是布局和我的.mp4视频文件 感谢