In my last post, I wrote about getting started with android studio which includes downloading and installing Android Studio. Now, its time to move forward and learn how to build your first android application or how android studio works. You can’t learn any software or language without practicing it. So, stop wasting your time on learning the theory for android development and move towards building your first application.
After installing android studio, you will see an android studio Welcome Screen.
Click on “Start New Project” from window above. You will see a window like:
Application Name: Write any Name you want to give to your Application.
Company name: When you upload your project on google store, all your applications are recognized by your company name. Company name should be something like “Name.example.com” as in my application, I choose “zainubwahid.example.com”
Package Name: After company name, your application on google store is specifically recognized by Package name. Because whenever you update your application, package name is used to recognize your application in devices.
Project location: The location, where you want to save your project.
Then click Next.
Select the platform for which you want to make an application. For example, in my case I selected Phone and Tablet. Then select the Minimum SDK. Minimum SDK means the minimum version of phone or tablet which can install your application. As I selected API 15(IceCream Sandwich).
Next step is selected activity for your application.
There are many activities available by default in android studio. Names of the activities show the functionality of activity. Here, I will recommend you selecting Blank Activity. With the passage of time, as you become familiar with android studio, you can select which activity you want. Or which activity suits your application.
Click” Next” for next step.
That is the last and most important step. Android development consists of two main important steps, I will call Front-end and Back-end. Here, front-end means layout/ presentation of your application. And back-end means back-end functionality of every screen/ activity. In simple words, you back-end is called as “Activity” and every Activity should have a layout screen called as “Layout”.
So, here in the above screen shot, write the activity name (Main activity, which will start on running your application). Write corresponding layout name (which will start and show the screen on running your application).
Title is the name of Activity you want to see on your device on starting that activity.
For example, in the above image, “Test” is the title of this activity.
Leave the Menu Resource Name at that time.
Best practice is to change the name and running the application again and again so that you can see the differences and you will understand it properly. Doing it only as described here will not be that much fruitful. You have to practice by changing everything and understanding the functionality.
Now click finish.
Be patient. Don’t rush. After clicking on finish, it will take some time to build your application.
After that, your first application is build and now you can edit it and write your code as you want.
Right now, it is not showing any layout. Sometimes “rendering Problem” may occur. And this is caused by SDKs. You can see little android image with a number “24”. This is called as ‘Android Version to use when rendering layouts’. Change this from 24 to 22/23 which is suitable for your android studio. Next also change the AppTheme. Change it to HOLO Dark/ HOLO LIGHT. As these are suitable for many android studios.
You can see two windows “MainActivity.java” and “activity_main.xml”. *.java file is called as Activity and *.xml is called as Layout.
Before changing any code, I will recommend you to run your app. For running, click on the green Play button in above tools named as “Run App”. Now wait and let your application build gradle and installing all required SDKs. It may take long time. Sometimes, depending on your processor, it can take even an hour to build the gradle for the first time.
After successful build, you will see a window:
This means, you app is successfully build and it has no error and is ready for launch. Now there are two methods to view your application before finalizing. One is “Choose a running device” and second is “Launch Emulator”.
Choose a Running Device: this means you can connect your android phone with laptop and android studio will detect it. ADB Driver installed in your PC will do this for you. It will detect your device and automatically installs your application on your android device. You will see your android device’s name in above window. Then Select your device’s name and Click OK.
Launch Emulator: Emulator is virtual Android device, build by android studio and run your app in it.
Before launching emulator, make sure you have installed all the required SDKs.
I will recommend choose a running device option. Because, Emulator may take a lot of time. And will hang your PC as it requires minimum 3GB RAM. For Emulator, you have to build your own virtual device. You can do this by going to AVD Manager Window. AVD means “Android Virtual Device”.
And your Android studio is installed successfully and ready for building your own Application.
I hope this will be helpful for a lot of people who still have any confusion! Please Comment, if you find and confusion or need any help.