Pages

Build your first Android App with Android Studio

Android Studio is the go-to tool to build an interactive and secure mobile app. Android Studio projects allow you to develop an interactive and reliable application that can be processed by people with just a few clicks. 

In this article, we have included the steps to create an app with Android Studio. Follow, the below-given instructions to build an app for your Android device. 


Build a basic app and run

The below-given steps will help you build and run a simple application with Android Studio for your Android device. 

Step 1: Install Android Studio to your system

  • First and foremost, you need to install Android Studio to get started.

  • Use the instructions to download and install Android Studio to your system and build your first mobile application.


                                             Source: instructables.com

Step 2: Create a new project 

Now that you have successfully downloaded and installed Android Studio, it's time to create a new project for mobile app development

                                                      Source: instructables.com



                                                      Source: instructables.com


  • Open Android Studio

  • Below the ‘Quick Start’ menu, choose the ‘Start a new Android Studio project’ option. 

  • A new window will open with the name ‘Create New Project’. Name your project ‘HelloWorld’ or according to your preference. 

  • Click ‘Next’ after naming a project. 

  • Make sure that you checked only the ‘Phone or Tablet’ option here. 

  • In case you are planning to test your app on mobile, make sure that SDK must have below your mobile’s operating system. 

  • After this, click on the ‘Next’ button.  

  • Leave all the options and activity fields as default.

  • Finally, click on the ‘Finish’ button.

Step 3: Update the welcome message in the Main Activity

                                    Source: instructables.com


  • Go to the activity_main.xml tab, if you are not automatically navigated there.

  • Open the Design tab on the activity_main.xml display.

  • Drag the “Hello World” text from the top left corner to the center of the screen. 

  • At the left side of the window click and open the ‘Value Folder’ in the ‘Project File System.’

  • In the ‘Value Folder’ file click on the ‘strings.xml file.’ 

  • Search for the “Hello World!” text in this file. 

  • After the “Hello World!” text add another text “Welcome to my app!”

  • Go back to the activity_main.xml tab. 

  • Now bring all the text “Hello World! Welcome to my app!” in the center of the screen. 

Step 4: Add a Button widget to the Main Activity

                                                Source: instructables.com


                                                         Source: instructables.com


  • Go to the ‘activity_main xml’ display and click on the ‘Design tab.’

  • Search for the ‘Button’ widget in the ‘Palette Menu’ which is displayed at the left of your mobile.

  • Click on the ‘Button’ and drag it to the center of the display below the welcome message.  

  • Ensure that the Button widget is still selected.

  • On the right side of the display, search for ‘Properties Menu’ and scroll down to find the ‘text’ field. 

  • Change the text to “Next Page” from “New Button.”

Step 5: Create a new Second Activity

                                                            Source: instructables.com


  • Search for the ‘App’ option in the ‘Project’s File System’.

  • Click on the New> Activity>Blank Activity.

  • Change the name of the activity to “Second Activity.”

  • Click on the ‘Finish’ button.

  • Ensure you are in the Design display of activity_second.xml.

  • Click and drag the text box to the center of the screen from the upper-left of the mobile. 

  • Make sure that the text box is selected and search for the ‘id’ field in the ‘Property menu’ and set the text to “text2.”

  • Open the strings.xml file again. 

  • Under the previous welcome message “Hello World! Welcome to my app!” add another welcome message “Welcome to the second page!”

  • Go back to the ‘activity_second.xml.’

  • Again choose the text box. 

  • Navigate to the Properties pane and set the “text” field to “@string/second_page.”

  • Ensure that your text box reads the new message “Welcome to my second page!” Plus the message should be in the center of the display. 

Step 6: Write the code for the Button “onClick” Method

  • Select the top of the work environment and the MainActivity.java tab. 

  • Now, add the below-given code at the end of the method onCreate.

Button button = (Button) findViewById(R.id.button);

button.setOnClickListener(new View.onClickListener() {

@Override

public void onClick(View v) {

goToSecondActivity();

}

});


  • Add the below-given code under the MainActivity class.

private void goToSecondActivity() {

Intent intent = new Intent(this, SecondActivity.class);

startActivity(intent);

}

  • Tap on the ‘+ next’ in order to import MainActivity.java third line to further expand the import statements. 

  • Lastly, add the statements given below at the end of the statements if they are missing from there. 

import android.content.Intent;

import android.view.View;

import android.widget.TextView;

Step 7: Finally test the App

                                                    Source: instructables.com




                                                        Source: instructables.com


  • Tap on the green play symbol which is present at the top of the Android Studio window in the toolbar. 

  • A new window with ‘Choose Device’ will appear. Now choose the ‘Launch emulator’ option. 

  • Click on the ‘OK’ button. 

  • As soon as the emulator will open (this might take some time), your app will automatically be launched on the virtual mobile. 

  • Once it is launched, ensure that the text is displayed at the center and the Button takes you to the next page. 


No comments:

Post a Comment

Make new Model/Controller/Migration in Laravel

  In this article, we have included steps to create a model and controller or resource controller with the help of command line(CLI). Here w...