
- #USING INTENTS TO OPEN ANY FILE ANDROID HOW TO#
- #USING INTENTS TO OPEN ANY FILE ANDROID ANDROID#
- #USING INTENTS TO OPEN ANY FILE ANDROID CODE#
PutExtra() : This method sends the data to another activity and in parameter, we have to pass key-value pair. String fullName = edittextfullname.getText().toString() Īs you can see that we have made a variable of fullName and it's of String data type.Įdittextfullname.getText().toString() : This means when the user enters the name in edittextfullname we get the entered value from this method with the help of getText() and then the value or name is converted in to string by using toString(). It comes from edittextfullname when the user enters any name in EditTexts it is stored in edittextfullname using the below code. So here we have to pass the data of fullName and hence we have given a unique key as full_name and value as fullName.
#USING INTENTS TO OPEN ANY FILE ANDROID CODE#
We have to add putExtra() method in onClick() as shown in the below code and in parameter we have to mention key and its value. Now, where we have to mention putExtra() method ? To pass the data through Intent we will use putExtra() method and in parameter, we will use Key-Value Pair. When you press Login Button it will successfully open the SecondActivity. Intent intent = new Intent(LoginActivity.this,SecondActivity.class) startActivity(intent) The below code adds into the onClick method. StartActivity(intent) : This starts the activity. Source: It means the current activity in which you are present.ĭestination: It means the activity where you have to go. Intent intent = new Intent(Source, Destination) startActivity(intent) If we have to open one activity from another activity we have to add an Intent code in onClick(View view) method as shown below. Whats Next ? Now we have to create a new activity so let’s create an activity with the same procedure we have gone through in the previous article. We have successfully linked the views defined in the activity_login with LoginActivity. Loginbutton=findViewById(R.id.LoginButton) :This line does the same thing as edittextfullname and edittextusername does. Now lets link the views using findViewById in LoginActivity.Įdittextfullname=findViewById(R.id.editTextFullName) : This line help to find the id by findViewById method and the id which we have given for widget in l ayout XML file.Įdittextusername=findViewById(R.id.editTextUserName) : This line does the same thing as edittextfullname does. Here we have given edittextfullname and edittextusername.īutton loginbutton : Here we have defined a button with name loginbutton. public class LoginActivity extends AppCompatActivity ĮditText edittextfullname,edittextusername : This is the way to define the views which we have used in the layout and you can give any name you want. Lets initialize them in our LoginActivity.



#USING INTENTS TO OPEN ANY FILE ANDROID HOW TO#
In the previous article, we designed the Login Page and now we will learn how to use Intent to pass data from LoginActivity to the next activity.įirst of all, we have to link the views of activity_login.xml with LoginActivity In activity_login.xml, we have used two EditTexts and one button. Through Intent we can move from one activity to another activity and Intent can also be used to pass the data from one activity to another activity. In this tutorial, we will learn how to use Intent and then we will pass the data using Intent from one activity to another.
#USING INTENTS TO OPEN ANY FILE ANDROID ANDROID#
Passing data between Activities using Intent in Android
