How to Pass Video Using Intent Between Activities in Android?
In android, An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
What we are going to build in this article?
In this article, we will learn that how we can pass Video using Intent between two activities and then play that video in the second activity. Here is a sample video of what we are going to build in this application. Note that we are going to implement this application using Java language.
Step by Step Implementation
Step 1: Create a New Project
- Open a new project.
- We will be working on Empty Activity with language as Java. Leave all other options unchanged.
- You can change the name of the project at your convenience.
- There will be two default files named activity_main.xml and MainActivity.java.
If you don’t know how to create a new project in Android Studio then you can refer to How to Create/Start a New Project in Android Studio?
Step 2: Adding storage permission
Follow the path app > manifests > AndroidManifest.xml and paste the following piece of code in it.
Step 3: Working on XML files
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Follow the path app > right click > new > activity > Empty Activity > name it as “MainActvity2”. Navigate to the app > res > layout > activity_main2.xml and add the below code to that file. Below is the code for the activity_main2.xml file.
Step 4: Working on java files
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Go to the MainActivity2.java file and refer to the following code. Below is the code for the MainActivity2.java file. Comments are added inside the code to understand the code in more detail.
Here is the final output of our application.
Please Login to comment...