Introduction: How to Create an Android App With Android Studio

Picture of How to Create an Android App With Android Studio

This tutorial will teach you the basics of how to build an Android app using the Android Studio development environment. As Android devices become increasingly more common, demand for new apps will only increase. Android Studio is an easy to use (and free) development environment to learn on. It's best if one has a working knowledge of the Java programming language for this tutorial because it is the language used by Android. There won't be much code used in this tutorial, so I will assume that you know enough Java to understand or are willing to look up what you don't know. This will take roughly 30-60 minutes, depending on how quickly you are able to download and install Android Studio. After using this tutorial to create your first Android app, you'll be well on your way to a fun new hobby or possibly even a promising career in mobile development.

Step 1: Install Android Studio

Picture of Install Android Studio
  1. Go to http://developer.android.com/sdk/index.html to download Android Studio.
  2. Use the installer to install Android Studio following its instructions.

Step 2: Open a New Project

Picture of Open a New Project
  1. Open Android Studio.
  2. Under the "Quick Start" menu, select "Start a new Android Studio project."
  3. On the "Create New Project" window that opens, name your project "HelloWorld".
  4. If you choose to, set the company name as desired*.
  5. Note where the project file location is and change it if desired.
  6. Click "Next."
  7. Make sure on that "Phone and Tablet" is the only box that is checked.
  8. If you are planning to test the app on your phone, make sure the minimum SDK is below your phone's operating system level.
  9. Click "Next."
  10. Select "Blank Activity."
  11. Click "Next."
  12. Leave all of the Activity name fields as they are.
  13. Click "Finish."

*Note: It is typical naming convention in Android projects to set the company name as some form of "example.name.here.com".

Step 3: Edit the Welcome Message in the Main Activity

Picture of Edit the Welcome Message in the Main Activity
  1. Navigate to the activity_main.xml tab if it is not already open.
  2. Make sure that the Design tab is open on the activity_main.xml display.
  3. Click and drag the "Hello, world!" from the upper left corner of the phone display to the center of the screen.
  4. In the project file system on the left side of the window, open the values folder.
  5. In the values folder, double-click the strings.xml file.
  6. In this file, find the line "Hello world!".
  7. After the "Hello world!" message, add "Welcome to my app!"
  8. Navigate back to the activity_main.xml tab.
  9. Make sure that your centered text now reads "Hello world! Welcome to my app!"

Step 4: Add a Button to the Main Activity

Picture of Add a Button to the Main Activity
  1. Navigate to the Design tab of the activity_main.xml display.
  2. In the Palette menu to the left of the phone display, find Button (under the heading Widgets).
  3. Click and drag Button to be centered underneath your welcome message.
  4. Make sure your button is still selected.
  5. In the Properties menu (on the right side of the window), scroll down to find the field for "text."
  6. Change the text from "New Button" to "Next Page."

Step 5: Create a Second Activity

Picture of Create a Second Activity
  1. At the top of the project's file system tree, right click on "app."
  2. Navigate through to New > Activity > Blank Activity.
  3. Change the name of this activity to "SecondActivity".
  4. Click "Finish."
  5. Make sure you are in the Design view of activity_second.xml.
  6. Drag the text box in the upper left of the phone display down to the center as you did on the Main Activity.
  7. With the text box still selected, find the "id" field in the Properties menu on the right, and set it to "text2".
  8. Open strings.xml again.
  9. Add a new line under "Hello world! Welcome to my app!" that reads "Welcome to the second page!".
  10. Navigate back to activity_second.xml.
  11. Select the text box again.
  12. In the Properties pane, set the "text" field to "@string/second_page".
  13. Make sure that the text box now reads "Welcome to the second page!" and is in the center of the screen in the phone display.

Step 6: Write the Button's "onClick" Method

Picture of Write the Button's "onClick" Method
  1. Select the MainActivity.java tab along the top of the work environment.

2. Add the following lines of code at the end of the onCreate method:

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

button.setOnClickListener(new View.onClickListener() {

@Override

public void onClick(View v) {

goToSecondActivity();

}

});

3. Add the following method to the bottom of the MainActivity class:

private void goToSecondActivity() {

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

startActivity(intent);

}

4. Click the + next to import at the third line of MainActivity.java to expand the import statements.

5. Add the following to the end of the import statements if they are not already there:

import android.content.Intent;

import android.view.View;

import android.widget.TextView;

Step 7: Test the Application

Picture of Test the Application
  1. Click the green play symbol from the toolbar at the top of the Android Studio window.
  2. When the "Choose Device" dialog apperas (this may take a few moments), select the "Lauch emulator" option.
  3. Click OK.
  4. When the emulator opens (this too could take awhile), the app will automatically launch the app upon the virtual phone being unlocked.
  5. Make sure that all of your text displays correctly and that the button takes you to the next page.

Step 8: Up, Up, and Away!

Picture of Up, Up, and Away!

Congrats! You've now completed your first Android application with some basic functionality. Your finished app should have a page greeting the user and a button that takes the user to a second page.

From here you have the cursory knowledge you need to go on to learn all there is to know about Android application development.

Comments

ysharad (author)2017-12-13

Nice information. It is really helpful for me. Thanks for providing best information. keep us update with such valuable information.If anyone need Android Application Development then connect to Micrasystems Pvt.Ltd

AmeyaK (author)2017-03-06

very helpful for beginner...!! Thanks

brainrosser63 (author)AmeyaK2017-12-08

Hello

Shakeel2476 made it! (author)2017-11-19

Yep... I made it using android studio (certainly with some changes).

Wow good

Hope we talk better on hangout if you don't mind,I have a lot of things to ask you and to tell you

RishavA5 (author)2017-11-29

I want to make an app that runs on all android devices and also without a companion app, can you please suggest how can i do so....like i created an app and put the apk file in my phone and installed it...and it ran

plzzz help

Louise Hudson (author)2017-09-06

Android Studio is very helpful I created many apps using it. One of my trending app on play store, I bought the template from AppnGameReskin in very low price and edited it in android studio and I got a unique app of my own

HacKingM1 (author)Louise Hudson2017-11-18

which app of yours is in play store tell me apps name........i am also a game & application developer.......

I am new for android studio and i want to built an aap for our shop can you help me please....

KaranS126 (author)Louise Hudson2017-09-18

Hello Louise! Can you please tell me which programming language one has to know when it comes to creating an app?

Louise Hudson (author)KaranS1262017-09-18

@KaranS126

Some of the best language are now a days are swift for iOS and Java for Android But if you're going to develope a game then go for unity.

MpV5 (author)2017-11-09

I am getting the below error:

Error:Error occurred while communicating with CMake server. Check log

Consult IDE log for more details (Help | Show Log)

Could you please help me?

Thanks in advance

sivaranjanreddy (author)2017-10-27

hi sir

i want to create a app for androide phone

but i dont have much knowledge on java

but i want to create it.

how ot is possible

can you help me

SwapnilK38 made it! (author)2017-10-26

hello i want to make app for my village and publish the sercives available in the town by app could you help me out for this ?

SM57 (author)2017-09-29

Step 3.1: "Navigate to the activity_main.xml tab if it is not already open."

should read: "Navigate to [appname]/app/src/main/res/layout/activity_main.xml"

SM57 (author)SM572017-09-29

And yes, what other people said about capitalizing View.OnClickListener in step 6.2...

And coders; make absolutely sure your second activity is named "SecondActivity" in step 5.3 or the code in step 6.3 will not work!

Van DucL (author)2017-08-09

Dear good friend,

Your instruction is very helpful and suitable to the beginner, especially for me. And I feel it excellent.

However, since I am so new to follow up your guide.

On your instruction, there were some things not so clear to me, and I could not find out the right location to create required action as you guided.

Should you better upload the image for each action during your guide on the programming to create an Android project, or please kindly show me where I can find out these things.

Maybe, the versions of Android Studio you used in your guide and that from I did, are different !

So, could you help and show me more clearly and slowly, on the step-by-step process with illustrative images.

Many thanks

DATECHENGVN GROUP

VideozS (author)2016-12-05

my emulator doesn't open... and after open an error is VT-x and BIOS. blah ! blah ! blah ! please tell me solution to open my emulator.

vishalv52 (author)VideozS2016-12-16

Hey!.

On Windows, go to BIOS > advanced settings >

There should be an option to enable virtualization

Save and restart your system

sarathy234 (author)vishalv522017-08-03

thank uuuuuuu

devasmarty (author)vishalv522017-07-01

Hmm it's quit different dude

devasmarty (author)VideozS2017-07-01

Try nexus 5 emulator of x64/84

jeffgreinert (author)2017-07-26

It's been a few years since this very helpful Instructable was posted. The original post contained a couple of errors, and Android Studio has changed since then, so here's the adjustments you need to make to the original post to get it to work.

Step 2.10 Blank Activity is no longer an option in Android Studio. Use Empty Activity.

Step 6.2 As ingsocof1984 pointed out, you need to capitalize the first letter in the 2nd "onClickListener", like this:
button.setOnClickListener(new View.OnClickListener() {


Step 6.5 Again from ingsocof1984, you need to add another "import" statement. It's in the picture, but not the original text description.
"import android.widget.Button"

I couldn't get the text & buttons centered as described in the instructions, but it ran just fine. My final code looks like this: (Let's see if posting it keeps the spaces I used for indentation!)

---------------------
MainActivity.java
---------------------
package com.example.user.helloworld;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToSecondActivity();
}
});
}

private void goToSecondActivity() {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
}


-------------------------
SecondActivity.java
-------------------------
package com.example.user.helloworld;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}

RsnMeda (author)jeffgreinert2017-08-02

Thanks for this.
Noticed that "Blank" wasn't a thing, & the "Hello world!" text wasn't showing up in strings.xml, suspected it was outdated.

FreePvp (author)2017-07-23

Thank you so much!

MrNams (author)2017-07-13

great,thansk for sharing

davissa (author)2017-07-12

Hehehe great..

shahdhruvi (author)2016-12-16

I am not able to see my app in android emulator

devasmarty (author)shahdhruvi2017-07-01

Reinstall SDK in SDK manager and update another emulator

Huan5235 (author)2016-12-23

1,674 MB for downloading the Android Studio...

devasmarty (author)Huan52352017-07-01

Of course its good with eclipse

Mandy_K (author)2017-01-12

My Project in Running Even Android Virtual Device is pop up but my hello world screen is not shown ..... it is showing just default "android" over the screen ... please help me put how i can run my own project screen ... Thanks in advance

devasmarty (author)Mandy_K2017-07-01

Try another SDK pack

tejaswiTeju made it! (author)2017-02-02

Unable to dowmload the foolowing. Help me out

devasmarty (author)tejaswiTeju2017-07-01

It's an older version that you've installed into Windows 10 please uninstall this package completely and download the android studio in http://www.androidstudio.com/download fit worthy

asadhirmoge (author)2017-06-21

I have a great idea that i think is solution to a huge problem, looking for a great coder to partner up with to finish the app. if interested please contact me on

asadhirmoge@gmail.com

pravalive (author)2017-04-19

with out the company details.can't we create the app??

kushalk24 (author)2017-04-04

Guys I have a great idea for an app but I don't know how to build it.Help anyone?
my mail - kumarkushal71@gmail.com

nnoya (author)2017-04-04

Hi! I have an idea. a Great app that will be helpful. but I don't know how to make it ( still thinking how ). this application maybe helpful to those who own medium businesses. I don't know who's the right person to discuss this.

please help me.

thank you :)

please send email. Thank you.

n.rey_noya@yahoo.com

buki1959 (author)2017-03-06

when i run the app i am getting string types not allowed (at 'id' with value '@+id/') error help me fix it

moontechnolabs (author)2017-03-06

Thank you for post helpful tutorial for Newcomers user for Android development and learning user.

Abdul RazzaqB (author)2017-02-27

Error:Failed to find target with hash string 'android-24' in: C:\Android\sdk1

<a href="install.android.platform">Install missing platform(s) and sync project</a>

how to resolve

AshwinA18 (author)2017-02-24

i think you have to update your instructions, as the latest versions have half the stuff changed but other than that,this was brilliant

SeanG103 (author)2017-02-19

Hi Guys,

I cant see this bit under strings:


  1. Add a new line under "Hello world! Welcome to my app!" that reads "Welcome to the second page!".

See below:

What am i doing wrong?

SUMANT K (author)2017-02-02

It is very good way for app development

jasim12 (author)2017-01-18

I already android studio installed

jasim12 (author)2017-01-18

i dont't know how to devolep app please teach me

Huan5235 (author)2016-12-23

OK, sounda cool when I read about step 4: click and drag buttons?

Grey_Wolfe (author)2016-11-28

Pretty sure it is against ToS to external link to boost your own page.

Just giving you a head's up, in case you were unaware. I'd hate to see anyone banned for a simple mistake. :)

HarshulS (author)2016-06-09

i did not understand how to open the strings.xml page

About This Instructable

1,454,591views

1,792favorites

License:

More by TheZachBales:How To Create An Android App With Android Studio
Add instructable to: