Djenh Djenh - 21 days ago 5
Android Question

Playing movie at app starting

I would like to play a movie at the begning of my Android application. So I use this code but it generates this error :

android.view.WindowLeaked:MainActivity has leaked window 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);
}

}


Please how can I fix it. All I found on web are about displaying a Dialog but in my case it is a video.

Thanks

Answer

@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();
        
       
 }