Switching Two Intents Using Android Studio

Switching Two Intents Using Android Studio

android, TRENDZ, TUTORIALS

Switching Two Intents Using Android Studio




In this tutorial Switching Two Intents Using Android Studio we are gonna learn what is the intent and how to handle them. Here we switching between two intents by clicking the buttons on each intent.
This Switching Two Intents Using Android Studio lesson we are using the android studio 2.2.2 Version. So you guys are having the updated version or just update it now, and also it’ll runs in the previous versions too.
For the entire project user interface we use only the Relative Layout. The intent is here nothing but each screen in android is known as Intent. When we starts new activity it actually creates an separate intent too. Every activity must contain an intent to design and control the present screen.
To create a complicated applications we must be clear in the design planning. Here we first create the User Interface for the entire application we concentrate on. In this Switching Two Intents Using Android Studio we are actually uses two intent which means two screen.
In this tutorial we are gonna use two separate screens. First we design the main activity and the second screen. In this lesson we create two intents with blank activity named html activity and css activity.
Lets consider how to design our intents. Designing a screen in Android is like design a page in Website. Almost it has all the properties like the CSS(Cascading Style Sheet), we can learn its power in the upcoming lessons.
Lets start to create the two intent application,
Step 1: Create a New Project in Android Studio.
When we create the project we have to choose the blank activity and named it as a css.
activity_css.xml

In the above code is the Main Activity xml for its User Interface Designing. In this code we have some very basic style properties and elements like a Text View and the Button.
For this tutorial we can just copy and paste the code in the activity_css.xml we can discuss the components in the future upcoming lessons. Because we’ve to concentrate more logic other than the design components.
After Paste the above code, switch to the design view and the screen should looks like this,
Switching Two Intents Using Android Studio
Step 2: Create another activity
Switching Two Intents Using Android Studio
When Create a new activity named it as html. And now we have to design the another intent for the newly created activity.
activity_html.xml

The Switching Two Intents Using Android Studio above code is gives the second intent screen output like this in the design view,
Switching Two Intents Using Android Studio
You may notice that in both of the screens we have the buttons and the text view. Which is actually redirects to each other, it is a point to switch from one page to another page.
In the above tutorial we didn’t type any text directly, but we defined them in the string.xml file. You can find this string.xml file under the res -> values -> string.xml. Just copy and paste the below code in the string.xml file.
string.xml

Now its time to write the java file for do the logical functionalities to switch between intents using android studio. First initiate the button which is the key to switch to the next screen. The below is the code for the css.java.
css.java

In the above we didn’t do any extra stuff, but what we done at here is in the onClick constructor we create a new Intent object and pass the parameters for the next intent. Here we mention the html.class function to be the next intent file.
And then we comment to start the activity by calling its object i. Like we did in the above code.
And now run the project by click the run button in the top bar or press the key combination Shift + F10, and it runs the project. When it shows the MainActivity(css.java and activity_css.xml) screen, click the button GO TO HTML and it shows the another intent or the another second screen.
As like we told in our previous lesson we can use the inbuilt emulator or can use the third party emulators like Andy, Bluestack, or Genymotion ad more. These third party emulators executes our application pretty much faster than the default emulators.
And now we have another screen or intent then we should try the same above logic for this too. It will redirect us to our home page, which means the CSS Page.
html.java

You can notice that here we pass the css.class as a parameter which means we trigger the css file when we click the GO TO CSS Button.
Switching Two Intents Using Android Studio
In this lesson we almost gives the some next level features from our previous lesson. You can gain some knowledge about the intent, and how to create and connect with another activity.

Leave a Reply