‫Let's initialize the widgets of the main activity and add the functionality of this button that allows
‫the user when he clicks on this button to be directed to the second activity.
‫Go to the main activity and declare and initialize the widgets.
‫Don't miss to press alt plus enter to import the class of the button.
‫The edit text and the text view.
‫Now.
‫We declared and initialized these widgets.
‫The text view, edit, text and button.
‫Now I need to add the functionality to the button, so I'll use listeners.
‫BTN dot set on Click listener new view on Click Listener.
‫And here I need to direct the user to the second activity, but I need to get his name from the edit
‫text and pass it to the second activity.
‫In this video.
‫I want from you to focus with me because I am going to show you how to pass the data between activity.
‫First of all, let me get the user name and store it inside this user name string variable.
‫Edit text dot, get text dot.
‫toString It's very simple and we've done it before.
‫Here, I'll use explicit intent because I am navigating between the components of that same application
‫intent.
‫I equal new intent and here I need to press alt plus enter to import the intent class.
‫And here I need to pass two parameters the current position and the destination.
‫I need to pass this as the context and second activity dot class, which is the destination.
‫But here we have an error because this is not referred to a context.
‫So I need to pass a context package, context, jetpack application context, which returns a context
‫variable.
‫Later on we'll talk about context, don't worry, but just follow me.
‫Now here I need to pass the name to the second activity.
‫I'll start with the I intent dot put extra.
‫The put extra method is used to include additional data within an intent object.
‫This data is passed along with the intent and can be retrieved by the receiving component.
‫The put extra method is overloaded with various versions to accommodate different types of data such
‫as strings, integers, booleans and more complex objects that implement serializable or parsable interfaces.
‫So for that I can use put extra the key value.
‫The key I need to pass is the name.
‫You can see the name and the value, which is the username that I get from the edit text.
‫Here I am passing a key value key is name and value is username, which is get it from the user.
‫The last method that I need to call is the start activity.
‫So whenever you use intent, we need to use the start activity method.