Skip to main content

How to transfer from one activity to another in android

How to transfer from one activity to another in android







In android, if you want to transfer the user from your source activity ie, the main activity or the activity you are currently working on to another activity we can simply use the intent property of the android.

Syntax:-
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);


In this example:-
  • MainActivity:- This can be defined as the source activity or the activity on which you are currently working. In other words, it can also be defined as the activity from where you want to redirect the user to another activity of your application.

  • SecondActivity:- This can be defined as the destination activity. In other words, it is the activity where the user is redirected after the button click from the first activity ie, the MainActivity .
Note:- The first activity that is passed is always passed as the context ie, Name.this.
The Second activity that is passed will always be passed as the .class file because this activity not even compiled by the android studio.First, this activity is needed to be compiled after that the SDK will have the reference of this class and execute this activity further.

Types of Intent

There are two types of Intent found in the android. These are listed below:-
  • Implicit Intent:- These are intents that are called by the android itself and need not be called by the user. 
    • Examples of these intents are Send and many more.
  • Explicit Intent:-  These are the intents that need to be called by the user explicitly and the user can pass the custom source and destination in the parameter in the argument. 


Comments

Popular posts from this blog

C++ Program Finding The Absolute Value

#include<iostream> using namespace std; int main() { cout<<" enter any number"; cin>>num; if(num>0) { cout<<"The absolute value of number is:"<< num; } else { cout<<"The absolute value of number is :"<< -(num); } return 0; } OUTPUT Enter Any number: 2 The absolute value of number is 2