سؤال

Hi i want to know how to run a service in background of an activity like i am using a video view and i want it to run while other activity are running

how to do this? VideoView videoView =(VideoView)findViewById(R.id.videoView1);

            //Creating MediaController  
    MediaController mediaController= new MediaController(this);  
        mediaController.setAnchorView(videoView);          

          //specify the location of media file  
       Uri uri=Uri.parse(Environment.getExternalStorageDirectory() + "/video.mp4");

          //Setting MediaController and URI, then starting the videoView  
       videoView.setMediaController(mediaController);  
       videoView.setVideoURI(uri);          
       videoView.requestFocus();  
       videoView.start();  

can any one help me how to bind service with this video view so it run in background?

هل كانت مفيدة؟

المحلول

Context context=getApplicationContext();
VideoView videoView =(VideoView)context.findViewById(R.id.videoView1);

نصائح أخرى

You need to bind the Service to your Activity if you need to interact with it. You can pass your VideoView throw your IBinder implementation if you need to handle it through the service. You should also run the Service in the foreground if you want to avoid it getting killed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top