Site icon C1CTech

Getting Started with Android Application

<p>In this article&comma; we will talk about how to get started with the very first android application <strong>HelloWorld<&sol;strong>&period; So step by step we will talk about how to install Android Studio&comma; how to create android application HelloWorld&comma; its initial project structure and then we will talk about how to create and run your first Android app&comma; Hello World&comma; on an emulator and on a physical device&period;<&sol;p>&NewLine;<h3 id&equals;"title" class&equals;"style-scope google-codelab-step"><strong><span class&equals;"style-scope google-codelab-step" style&equals;"color&colon; &num;000080&semi;">Install Android Studio<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>Android Studio provides a complete integrated development environment &lpar;IDE&rpar; including an advanced code editor and a set of app templates&period;<br &sol;>&NewLine;In addition&comma; it contains tools for development&comma; debugging&comma; testing&comma; and performance that make it faster and easier to develop apps&period;<br &sol;>&NewLine;You can test your apps with a large range of preconfigured emulators or on your own mobile device&comma; build production apps&comma; and publish on the Google Play store&period;<&sol;p>&NewLine;<p>Note&colon; Android Studio is continually being improved&period; For the latest information on system requirements and installation instructions&comma; see<strong><span style&equals;"color&colon; &num;008000&semi;"><a style&equals;"color&colon; &num;008000&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;studio&sol;index&period;html"> Android Studio<&sol;a><&sol;span><&sol;strong>&period;<&sol;p>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Create Android Application <span class&equals;"style-scope google-codelab-step">Hello World<&sol;span><&sol;strong><&sol;span><&sol;h3>&NewLine;<ul type&equals;"1">&NewLine;<li>To create a simple Android Application using Android studio firstly click on Android studio icon <img class&equals;"alignnone wp-image-1127" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;android-150x150&period;jpg" alt&equals;"android" width&equals;"19" height&equals;"19" &sol;> &period; It will show the welcome screen as shown below&colon;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 60px&semi;"><img class&equals;" size-full wp-image-1117 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;start&lowbar;android&lowbar;proj&lowbar;nnew&period;png" alt&equals;"start&lowbar;android&lowbar;proj&lowbar;nnew" width&equals;"972" height&equals;"598" &sol;><&sol;p>&NewLine;<ul>&NewLine;<li>In welcome screen on the left side it is showing the list of projects you have but the first time it is empty&period;<&sol;li>&NewLine;<li>In the <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Welcome to Android Studio<&sol;strong><&sol;span> window&comma; click on <strong><span style&equals;"color&colon; &num;008000&semi;">Start a new Android Studio project<&sol;span>&period;<&sol;strong><&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 60px&semi;"><img class&equals;" size-full wp-image-1115 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;start&lowbar;android&lowbar;proj&lowbar;new-3242295379-1562237615237&period;png" alt&equals;"start&lowbar;android&lowbar;proj&lowbar;new" width&equals;"971" height&equals;"594" &sol;><&sol;p>&NewLine;<p>          Or if you have a project opened&comma; select <span style&equals;"color&colon; &num;008000&semi;"><strong>File &gt&semi; New &gt&semi; New Project<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<ul type&equals;"1">&NewLine;<li>Now<strong><span style&equals;"color&colon; &num;0000ff&semi;"> Choose your project<&sol;span> <&sol;strong>window appears&period; Select <strong><span style&equals;"color&colon; &num;008000&semi;">Phone and Tablet<&sol;span><&sol;strong> tab to create an application for phone and tablet&period; To create an app for smartwatches&comma; select <strong><span style&equals;"color&colon; &num;008000&semi;">Wear OS<&sol;span><&sol;strong>&comma; for TV applications select <strong><span style&equals;"color&colon; &num;008000&semi;">TV<&sol;span><&sol;strong> or you can select the other two options also ie&period; Android Auto and Android Things&period;<&sol;li>&NewLine;<li>In the <strong><span style&equals;"color&colon; &num;008000&semi;">Phone and Tablet<&sol;span><&sol;strong> tab&comma; Android Studio provides Activity templates to help you get started&period; An Android activity is one screen of the Android app&&num;8217&semi;s user interface&period; It is a crucial component of any Android app&period; An Activity typically has a layout associated with it that defines how UI elements appear on a screen&period; For the <span style&equals;"color&colon; &num;0000ff&semi;"><strong>HelloWorld<&sol;strong><&sol;span> project&comma; Inside <strong><span style&equals;"color&colon; &num;008000&semi;">Phone and Tablet<&sol;span><&sol;strong> tab choose <strong><span style&equals;"color&colon; &num;008000&semi;">Empty Activity<&sol;span><&sol;strong> as shown below&comma; and click <span style&equals;"color&colon; &num;008000&semi;"><strong>Next<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 60px&semi;"><img class&equals;"alignnone size-full wp-image-1118" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;create&lowbar;new&lowbar;project&period;png" alt&equals;"create&lowbar;new&lowbar;project" width&equals;"1127" height&equals;"853" &sol;><&sol;p>&NewLine;<ul type&equals;"1">&NewLine;<li>Now a new <strong><span style&equals;"color&colon; &num;0000ff&semi;">Configure your project<&sol;span> <&sol;strong>window will open&period; It will ask you about your Application name&comma; package name&comma; and location of the project&period; Enter <span style&equals;"color&colon; &num;0000ff&semi;"><strong>HelloWorld<&sol;strong><&sol;span><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;"> for the <&sol;span><span style&equals;"color&colon; &num;008000&semi;"><strong>Application name<&sol;strong><&sol;span><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">&period;<&sol;span><&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 60px&semi;"><img class&equals;"alignnone size-full wp-image-1119" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;configure&lowbar;project&lowbar;new&period;png" alt&equals;"configure&lowbar;project&lowbar;new" width&equals;"1070" height&equals;"783" &sol;><&sol;p>&NewLine;<ul type&equals;"1">&NewLine;<li>Enter the package name for your HelloWorld application&comma; you can leave this field as it is or you can change it&period; It plays an important role when you want to publish your app on play store&comma; it makes your app unique from other millions of application&period; In my case&comma; I have changed the package name to <span style&equals;"color&colon; &num;008000&semi;"><strong>com&period;c1ctech&period;helloworld<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<li>Verify that the default <span style&equals;"color&colon; &num;008000&semi;"><strong>Project location<&sol;strong><&sol;span> is where you want to store your Hello World app and other Android Studio projects or change it to your preferred directory&period;<&sol;li>&NewLine;<li>Select the language in which you want to create the application ie&period; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Java<&sol;strong><&sol;span> or <span style&equals;"color&colon; &num;0000ff&semi;"><strong>kotlin<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<li>The default minimum API level selected is <span style&equals;"color&colon; &num;008000&semi;"><strong>API 21&colon; Android 5&period;0&lpar;Lollipop&rpar;<&sol;strong><&sol;span>&comma; it ensures that your app will only be supported by Android version 5&period;0 and above but you can not install this app in Android version lower than 5&period;0&period; According to your selected API level&comma; it will show you the percent of devices in which your app will run&period;<&sol;li>&NewLine;<li>Leave unchecked <span style&equals;"color&colon; &num;008000&semi;"><strong>This project will support Instant apps<&sol;strong><&sol;span>&period; If your project requires additional components for your chosen target SDK&comma; Android Studio will install them automatically&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<ul>&NewLine;<li>Click <span style&equals;"color&colon; &num;008000&semi;"><strong>Finish<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Explore the Project structure of HelloWorld<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>Now we will explore how the project is organized in Android Studio&period;<&sol;p>&NewLine;<ul type&equals;"1">&NewLine;<li>When you first create an app project&comma; the <span style&equals;"color&colon; &num;008000&semi;"><strong>Project &gt&semi; Android<&sol;strong><&sol;span> pane appears with the <span style&equals;"color&colon; &num;0000ff&semi;"><strong>app<&sol;strong><&sol;span> and <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Gradle Scripts<&sol;strong><&sol;span> folder as shown below&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 60px&semi;"><img class&equals;"alignnone size-full wp-image-1133" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;android&lowbar;folder&lowbar;new&period;png" alt&equals;"android&lowbar;folder&lowbar;new" width&equals;"445" height&equals;"356" &sol;><&sol;p>&NewLine;<ul>&NewLine;<li>The expanded form of <span style&equals;"color&colon; &num;0000ff&semi;"><strong>app<&sol;strong><&sol;span> and <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Gradle Scripts<&sol;strong><&sol;span> folder of <span style&equals;"color&colon; &num;008000&semi;"><strong>HelloWorld<&sol;strong><&sol;span> application as shown below&colon;<&sol;li>&NewLine;<&sol;ul>&NewLine;<figure id&equals;"attachment&lowbar;1138" aria-describedby&equals;"caption-attachment-1138" style&equals;"width&colon; 637px" class&equals;"wp-caption aligncenter"><img class&equals;"alignnone size-full wp-image-1138" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;and&lowbar;proj&lowbar;stru-3530591771-1562675165112&period;png" alt&equals;"and&lowbar;proj&lowbar;stru" width&equals;"637" height&equals;"777" &sol;><figcaption id&equals;"caption-attachment-1138" class&equals;"wp-caption-text"><span style&equals;"color&colon; &num;000080&semi;"><strong>Application level project structure<&sol;strong><&sol;span><&sol;figcaption><&sol;figure>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p>1&period; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>AndroidManifest&period;xml<&sol;strong>&colon;<&sol;span><&sol;p>&NewLine;<p>Every project in Android includes a manifest file&comma; which is <a href&equals;"https&colon;&sol;&sol;www&period;geeksforgeeks&period;org&sol;application-manifest-file-android&sol;"><span style&equals;"color&colon; &num;008000&semi;"><strong>AndroidManifest&period;xml<&sol;strong><&sol;span> <&sol;a>&comma; stored in the <strong><span style&equals;"color&colon; &num;008000&semi;">app&gt&semi;manifests<&sol;span><&sol;strong> directory of the project structure&period; The manifest file is an important file of our app because it defines its components which include all activities&comma; services&comma; broadcast receivers&comma; and content providers&period;<&sol;p>&NewLine;<p>It describes the permission that Android apps must request to access sensitive user data &lpar;such as contacts and SMS&rpar; or certain system features &lpar;such as the camera and internet access&rpar;&period;<&sol;p>&NewLine;<p>It also contains information about what types of hardware or software features your app requires&comma; and thus&comma; which types of devices your app is compatible with&period; Google Play Store does not allow your app to be installed on devices that don&&num;8217&semi;t provide the features or system version that your app requires&period;<&sol;p>&NewLine;<p>The default <span style&equals;"color&colon; &num;008000&semi;"><strong>AndroidManifest&period;xml<&sol;strong> <&sol;span>file looks like as shown below&colon;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>AndroidManifest&period;xml<&sol;strong><&sol;span><&sol;p>&NewLine;<pre><strong>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;manifest xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; package&equals;"com&period;c1ctech&period;helloworld"&gt&semi;&NewLine;&NewLine; &lt&semi;application&NewLine; android&colon;allowBackup&equals;"true"&NewLine; android&colon;icon&equals;"&commat;mipmap&sol;ic&lowbar;launcher"&NewLine; android&colon;label&equals;"&commat;string&sol;app&lowbar;name"&NewLine; android&colon;roundIcon&equals;"&commat;mipmap&sol;ic&lowbar;launcher&lowbar;round"&NewLine; android&colon;supportsRtl&equals;"true"&NewLine; android&colon;theme&equals;"&commat;style&sol;AppTheme"&gt&semi;&NewLine; &lt&semi;activity android&colon;name&equals;"&period;MainActivity"&gt&semi;&NewLine; &lt&semi;intent-filter&gt&semi;&NewLine; &lt&semi;action android&colon;name&equals;"android&period;intent&period;action&period;MAIN" &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;category android&colon;name&equals;"android&period;intent&period;category&period;LAUNCHER" &sol;&gt&semi;&NewLine; &lt&semi;&sol;intent-filter&gt&semi;&NewLine; &lt&semi;&sol;activity&gt&semi;&NewLine; &lt&semi;&sol;application&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;manifest&gt&semi;<&sol;strong><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p>2&period; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Java<&sol;strong><&sol;span> &colon;<&sol;p>&NewLine;<p>The <span style&equals;"color&colon; &num;008000&semi;"><strong>java<&sol;strong><&sol;span> folder includes Java class files in three subfolders&period;The <span style&equals;"color&colon; &num;008000&semi;"><strong>com&period;c1ctech&period;helloworld<&sol;strong><&sol;span> &lpar;or the package name you have specified&rpar; folder contains all the java files for an app package&period; The other two folders are used for testing&period; Mainly&comma; these java files get the data from the Layout file and after processing that data output will be shown in the UI layout&period; It works on the backend of an Android application&period;The <span style&equals;"color&colon; &num;0000ff&semi;"><strong>com&period;c1ctech&period;helloworld<&sol;strong><&sol;span> contains <strong><span style&equals;"color&colon; &num;008000&semi;">MainActivity&period;java <&sol;span><&sol;strong><span style&equals;"color&colon; &num;000000&semi;">which is t<&sol;span>he name of the first <span style&equals;"color&colon; &num;008000&semi;"><strong>Activity<&sol;strong><&sol;span> &lpar;screen&rpar; the user sees&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>MainActivity&period;java<&sol;strong><&sol;span><&sol;p>&NewLine;<pre><strong>package com&period;c1ctech&period;helloworld&semi;&NewLine;&NewLine;import android&period;support&period;v7&period;app&period;AppCompatActivity&semi;&NewLine;import android&period;os&period;Bundle&semi;&NewLine;&NewLine;public class MainActivity extends AppCompatActivity &lbrace;&NewLine;&NewLine; &commat;Override&NewLine; protected void onCreate&lpar;Bundle savedInstanceState&rpar; &lbrace;&NewLine; super&period;onCreate&lpar;savedInstanceState&rpar;&semi;&NewLine; setContentView&lpar;R&period;layout&period;activity&lowbar;main&rpar;&semi;&NewLine; &rcub;&NewLine;&rcub;<&sol;strong><&sol;pre>&NewLine;<p>3&period; <span style&equals;"color&colon; &num;0000ff&semi;"><b>drawable<&sol;b><&sol;span>&colon;<&sol;p>&NewLine;<p>This folder contains drawable resources which define various graphics with bitmaps&lpar;PNG&comma; JPEG&rpar; or XML&period; Drawable resources are accessed from the <strong><span style&equals;"color&colon; &num;008000&semi;">R&period;drawable<&sol;span><&sol;strong> class&period;<&sol;p>&NewLine;<p>4&period; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>layout<&sol;strong><&sol;span>&colon;<&sol;p>&NewLine;<p>This folder contains layout resource which defines the architecture for the UI in an Activity or a component of a UI&period; It can be accessed from the <strong><span style&equals;"color&colon; &num;008000&semi;">R&period;layout<&sol;span><&sol;strong> class&period; By default it contains <span style&equals;"color&colon; &num;008000&semi;"><strong>activity&lowbar;main&period;xml<&sol;strong><&sol;span> layout corresponding to <span style&equals;"color&colon; &num;008000&semi;"><strong>MainActivity&period;java<&sol;strong><&sol;span> looks like as shown below&colon;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">activity&lowbar;main&period;xml<&sol;span><&sol;strong><&sol;p>&NewLine;<pre><strong>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;android&period;support&period;constraint&period;ConstraintLayout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; tools&colon;context&equals;"&period;MainActivity"&gt&semi;&NewLine;&NewLine; &lt&semi;TextView&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; android&colon;text&equals;"Hello World&excl;"&NewLine; app&colon;layout&lowbar;constraintBottom&lowbar;toBottomOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintLeft&lowbar;toLeftOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintRight&lowbar;toRightOf&equals;"parent"&NewLine; app&colon;layout&lowbar;constraintTop&lowbar;toTopOf&equals;"parent" &sol;&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;android&period;support&period;constraint&period;ConstraintLayout&gt&semi;<&sol;strong><&sol;pre>&NewLine;<p>5&period; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>mipmap<&sol;strong><&sol;span>&colon;<&sol;p>&NewLine;<p>The <strong><span style&equals;"color&colon; &num;008000&semi;">res&sol;mipmap <&sol;span><&sol;strong>contains your app-launcher icons &lpar;icon displayed on the home screen&rpar; for various screen resolutions&period;<&sol;p>&NewLine;<p>6&period; <span style&equals;"color&colon; &num;0000ff&semi;"><strong>values<&sol;strong><&sol;span>&colon;<&sol;p>&NewLine;<p>The <strong><span style&equals;"color&colon; &num;008000&semi;">res&sol;values<&sol;span> <&sol;strong>folder is used to store the values for the resources that are used in many Android projects to include features of color&comma; styles&comma; dimensions etc&period;<&sol;p>&NewLine;<p>7&period; <strong><span style&equals;"color&colon; &num;0000ff&semi;">colors&period;xml<&sol;span><&sol;strong>&colon;<&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<p>colors&period;xml  is used to store a color value &lpar;a hexadecimal color&rpar;&period; Different color values are identified by a unique name that can be used in the Android application program&period;<&sol;p>&NewLine;<pre><strong>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;resources&gt&semi;&NewLine; &lt&semi;color name&equals;"colorPrimary"&gt&semi;&num;008577&lt&semi;&sol;color&gt&semi;&NewLine; &lt&semi;color name&equals;"colorPrimaryDark"&gt&semi;&num;00574B&lt&semi;&sol;color&gt&semi;&NewLine; &lt&semi;color name&equals;"colorAccent"&gt&semi;&num;D81B60&lt&semi;&sol;color&gt&semi;&NewLine;&lt&semi;&sol;resources&gt&semi;<&sol;strong><&sol;pre>&NewLine;<p>8&period; <strong><span style&equals;"color&colon; &num;0000ff&semi;">strings&period;xml<&sol;span><&sol;strong>&colon;<&sol;p>&NewLine;<p>strings&period;xml is to define the strings&comma; string arrays in one file so that it is easy to use the same string in different positions in the android project plus it makes the project looks less messy&period;<&sol;p>&NewLine;<pre><strong>&lt&semi;resources&gt&semi;&NewLine; &lt&semi;string name&equals;"app&lowbar;name"&gt&semi;HelloWorld&lt&semi;&sol;string&gt&semi;&NewLine;&lt&semi;&sol;resources&gt&semi;<&sol;strong><&sol;pre>&NewLine;<p>9&period; <strong><span style&equals;"color&colon; &num;0000ff&semi;">style&period;xml<&sol;span><&sol;strong>&colon;<&sol;p>&NewLine;<p>style&period;xml is used to define the look and format for a UI &period; A style can be applied to an individual <strong><span style&equals;"color&colon; &num;008000&semi;">View<&sol;span><&sol;strong> &lpar;from within a layout file&rpar; or to an entire <span style&equals;"color&colon; &num;008000&semi;"><strong>Activity<&sol;strong><&sol;span> or application &lpar;from within the manifest file&rpar;&period;<&sol;p>&NewLine;<pre><strong>&lt&semi;resources&gt&semi;&NewLine;&NewLine; &lt&semi;&excl;-- Base application theme&period; --&gt&semi;&NewLine; &lt&semi;style name&equals;"AppTheme" parent&equals;"Theme&period;AppCompat&period;Light&period;DarkActionBar"&gt&semi;&NewLine; &lt&semi;&excl;-- Customize your theme here&period; --&gt&semi;&NewLine; &lt&semi;item name&equals;"colorPrimary"&gt&semi;&commat;color&sol;colorPrimary&lt&semi;&sol;item&gt&semi;&NewLine; &lt&semi;item name&equals;"colorPrimaryDark"&gt&semi;&commat;color&sol;colorPrimaryDark&lt&semi;&sol;item&gt&semi;&NewLine; &lt&semi;item name&equals;"colorAccent"&gt&semi;&commat;color&sol;colorAccent&lt&semi;&sol;item&gt&semi;&NewLine; &lt&semi;&sol;style&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;resources&gt&semi;<&sol;strong><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p>10&period; <b><span style&equals;"color&colon; &num;0000ff&semi;">build&period;gradle&lpar;Project&colon; helloworld&rpar;<&sol;span>&colon;<&sol;b><&sol;p>&NewLine;<p><b> <&sol;b>This is where you&&num;8217&semi;ll find the configuration options that are common to all of the modules that make up your project&period; Every Android Studio project contains a single&comma; top-level Gradle build file&period; Most of the time&comma; you won&&num;8217&semi;t need to make any changes to this file&comma; but it&&num;8217&semi;s still useful to understand its contents&period;<&sol;p>&NewLine;<p>Given below is the <span style&equals;"color&colon; &num;008000&semi;"><strong>build&period;gradle&lpar;<b>Project&colon; helloworld<&sol;b>&rpar;<&sol;strong><&sol;span> file for the HelloWorld app&colon;<&sol;p>&NewLine;<pre><strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; Top-level build file where you can add configuration options common to all sub-projects&sol;modules&period;<&sol;span>&NewLine;&NewLine;buildscript &lbrace;&NewLine; repositories &lbrace;&NewLine; google&lpar;&rpar;&NewLine; jcenter&lpar;&rpar;&NewLine; &NewLine; &rcub;&NewLine; dependencies &lbrace;&NewLine; classpath 'com&period;android&period;tools&period;build&colon;gradle&colon;3&period;4&period;1'&NewLine; &NewLine; &sol;&sol; NOTE&colon; Do not place your application dependencies here&semi; they belong&NewLine; &sol;&sol; in the individual module build&period;gradle files&NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;allprojects &lbrace;&NewLine; repositories &lbrace;&NewLine; google&lpar;&rpar;&NewLine; jcenter&lpar;&rpar;&NewLine; &NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;task clean&lpar;type&colon; Delete&rpar; &lbrace;&NewLine; delete rootProject&period;buildDir&NewLine;&rcub;<&sol;strong><&sol;pre>&NewLine;<p><b>11&period; <span style&equals;"color&colon; &num;0000ff&semi;">build&period;gradle&lpar;Module&colon; app&rpar;<&sol;span><&sol;b>&colon;<&sol;p>&NewLine;<p>This file defines the module-specific build configurations&period; In addition to the project-level <code>build&period;gradle<&sol;code> file&comma; each module has a <code>build&period;gradle<&sol;code> file of its own&comma; which allows you to configure build settings for each specific module &lpar;the HelloWorld app has only one module&rpar;&period;<&sol;p>&NewLine;<p>Given below is the <span style&equals;"color&colon; &num;008000&semi;"><strong>build&period;gradle&lpar;Module&colon;app&rpar;<&sol;strong><&sol;span> file for the HelloWorld app&colon;<&sol;p>&NewLine;<pre><strong>apply plugin&colon; 'com&period;android&period;application'&NewLine;&NewLine;android &lbrace;&NewLine; compileSdkVersion 28&NewLine; defaultConfig &lbrace;&NewLine; applicationId "com&period;c1ctech&period;helloworld"&NewLine; minSdkVersion 21&NewLine; targetSdkVersion 28&NewLine; versionCode 1&NewLine; versionName "1&period;0"&NewLine; testInstrumentationRunner "android&period;support&period;test&period;runner&period;AndroidJUnitRunner"&NewLine; &rcub;&NewLine; buildTypes &lbrace;&NewLine; release &lbrace;&NewLine; minifyEnabled false&NewLine; proguardFiles getDefaultProguardFile&lpar;'proguard-android-optimize&period;txt'&rpar;&comma; 'proguard-rules&period;pro'&NewLine; &rcub;&NewLine; &rcub;&NewLine;&rcub;&NewLine;&NewLine;dependencies &lbrace;&NewLine; implementation fileTree&lpar;dir&colon; 'libs'&comma; include&colon; &lbrack;'&ast;&period;jar'&rsqb;&rpar;&NewLine; implementation 'com&period;android&period;support&colon;appcompat-v7&colon;28&period;0&period;0'&NewLine; implementation 'com&period;android&period;support&period;constraint&colon;constraint-layout&colon;1&period;1&period;3'&NewLine; testImplementation 'junit&colon;junit&colon;4&period;12'&NewLine; androidTestImplementation 'com&period;android&period;support&period;test&colon;runner&colon;1&period;0&period;2'&NewLine; androidTestImplementation 'com&period;android&period;support&period;test&period;espresso&colon;espresso-core&colon;3&period;0&period;2'&NewLine;&rcub;<&sol;strong><&sol;pre>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Running the Application<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>Let&&num;8217&semi;s try to run our <b><span style&equals;"color&colon; &num;008000&semi;">HelloWorld<&sol;span>&excl;<&sol;b> application we just created&period;<&sol;p>&NewLine;<h4 id&equals;"title" class&equals;"style-scope google-codelab-step"><span style&equals;"color&colon; &num;000080&semi;"><strong><span class&equals;"style-scope google-codelab-step">Use a virtual device &lpar;emulator&rpar;<&sol;span><&sol;strong><&sol;span><&sol;h4>&NewLine;<p>Before running the application on virtual device firstly we will use the <span style&equals;"color&colon; &num;008000&semi;"><strong><a style&equals;"color&colon; &num;008000&semi;" href&equals;"http&colon;&sol;&sol;developer&period;android&period;com&sol;tools&sol;devices&sol;managing-avds&period;html">Android Virtual Device &lpar;AVD&rpar; manager<&sol;a><&sol;strong><&sol;span> to create a virtual device &lpar;also known as an emulator&rpar; that simulates the configuration for a particular type of Android device&comma; and use that virtual device to run the app&period;<&sol;p>&NewLine;<p>Using the AVD Manager&comma; you define the hardware characteristics of a device&comma; its API level&comma; storage&comma; resolution and other properties and save it as a virtual device&period; With virtual devices&comma; you can test apps on different device configurations &lpar;such as tablets and phones&rpar; with different API levels&comma; without having to use physical devices&period;<&sol;p>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong> Create an Android virtual device &lpar;AVD&rpar;<&sol;strong><&sol;span><&sol;h5>&NewLine;<p>In order to run an emulator on your computer&comma; you have to create a configuration that describes the virtual device&period;<&sol;p>&NewLine;<ul>&NewLine;<li>In Android Studio&comma; select <span style&equals;"color&colon; &num;008000&semi;"><strong>Tools &gt&semi; Android &gt&semi; AVD Manager<&sol;strong><&sol;span>&comma; or click the AVD Manager icon <img class&equals;"alignnone wp-image-1128" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;avd&period;png" alt&equals;"avd" width&equals;"26" height&equals;"26" &sol;>  in the toolbar&period; The <strong><span style&equals;"color&colon; &num;0000ff&semi;">Your Virtual Devices<&sol;span> <&sol;strong>screen appears&period; If you&&num;8217&semi;ve already created virtual devices&comma; the screen shows them &lpar;as shown in the figure below&rpar;&semi; otherwise you see a blank list&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 30px&semi;"><img class&equals;"alignnone size-full wp-image-1120" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;virtual&lowbar;device&period;png" alt&equals;"virtual&lowbar;device" width&equals;"1211" height&equals;"656" &sol;><&sol;p>&NewLine;<ul>&NewLine;<li>Click the<span style&equals;"color&colon; &num;008000&semi;"><strong> &plus;Create Virtual Device<&sol;strong><&sol;span>&period; The <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Select Hardware<&sol;strong><&sol;span> window appears showing a list of pre-configured hardware devices&period; For each device&comma; the table provides a column for its diagonal display size &lpar;<strong>Size<&sol;strong>&rpar;&comma; screen resolution in pixels &lpar;<strong>Resolution<&sol;strong>&rpar;&comma; and pixel density &lpar;<strong>Density<&sol;strong>&rpar;&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 30px&semi;"><img class&equals;"alignnone size-full wp-image-1121" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;select&lowbar;hardware-3975169854-1562264392207&period;png" alt&equals;"select&lowbar;hardware" width&equals;"1120" height&equals;"776" &sol;><&sol;p>&NewLine;<ul>&NewLine;<li>Choose a device such as <strong>Nexus 5<&sol;strong> or <strong>Pixel XL<&sol;strong>&comma; and click <span style&equals;"color&colon; &num;008000&semi;"><strong>Next<&sol;strong><&sol;span>&period; The <span style&equals;"color&colon; &num;0000ff&semi;"><strong>System Image <&sol;strong><&sol;span>screen appears&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 30px&semi;"><img class&equals;"alignnone size-full wp-image-1123" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;system&lowbar;image&period;png" alt&equals;"system&lowbar;image" width&equals;"1047" height&equals;"828" &sol;><&sol;p>&NewLine;<ul>&NewLine;<li>Click the <span style&equals;"color&colon; &num;008000&semi;"><strong>Recommended<&sol;strong><&sol;span> tab if it is not already selected&comma; and choose which version of the Android system to run on the virtual device &lpar;such as <strong>Oreo<&sol;strong>&rpar;&period;There are many more versions available than shown in the <strong style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">Recommended<&sol;strong><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;"> tab&period; Look at the <&sol;span><strong style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">x86 Images<&sol;strong><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;"> and <&sol;span><strong style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">Other Images <&sol;strong><span style&equals;"color&colon; var&lpar;--color-text&rpar;&semi;">tabs to see them&period;<&sol;span><&sol;li>&NewLine;<li>If a <strong>Download<&sol;strong> link is visible next to a system image you want to use&comma; it is not installed yet&period; Click the link to start the download&comma; and click <strong>Finish<&sol;strong> when it&&num;8217&semi;s done&period;<&sol;li>&NewLine;<li>After choosing a system image&comma; click <span style&equals;"color&colon; &num;008000&semi;"><strong>Next<&sol;strong><&sol;span>&period; The <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Android Virtual Device &lpar;AVD&rpar;<&sol;strong><&sol;span> window appears&period; You can also change the name of the AVD&period; Check your configuration and click <span style&equals;"color&colon; &num;008000&semi;"><strong>Finish<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p style&equals;"padding-left&colon; 30px&semi;"><img class&equals;"alignnone size-full wp-image-1124" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;avd&lowbar;window&period;png" alt&equals;"avd&lowbar;window" width&equals;"1048" height&equals;"784" &sol;><&sol;p>&NewLine;<h5><&sol;h5>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Run the app on the virtual device<&sol;strong><&sol;span><&sol;h5>&NewLine;<p>Now you will finally run your HelloWorld app&period;<&sol;p>&NewLine;<ol>&NewLine;<li>In Android Studio&comma; choose <span style&equals;"color&colon; &num;008000&semi;"><strong>Run &gt&semi; Run app<&sol;strong><&sol;span> or click the <span style&equals;"color&colon; &num;008000&semi;"><strong>Run<&sol;strong><&sol;span> icon in the toolbar&period;<&sol;li>&NewLine;<li>The <span style&equals;"color&colon; &num;0000ff&semi;"><strong>Select Deployment Target<&sol;strong><&sol;span> window&comma; under <span style&equals;"color&colon; &num;008000&semi;"><strong>Available Virtual Devices<&sol;strong><&sol;span>&comma; select the virtual device&comma; which you just created&comma; and click <span style&equals;"color&colon; &num;008000&semi;"><strong>OK<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ol>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1125" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;select&lowbar;device-1&period;png" alt&equals;"select&lowbar;device" width&equals;"781" height&equals;"606" &sol;><&sol;p>&NewLine;<p>The emulator starts and boots just like a physical device&period; Depending on the speed of your computer&comma; this may take a while&period; Your app builds&comma; and once the emulator is ready&comma; Android Studio will upload the app to the emulator and run it&period;<&sol;p>&NewLine;<p>You should see the <strong><span style&equals;"color&colon; &num;008000&semi;">HelloWorld<&sol;span><&sol;strong> app as shown in the following figure&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone wp-image-1126" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;Screenshot&lowbar;1562244111-576x1024&period;png" alt&equals;"Screenshot&lowbar;1562244111" width&equals;"356" height&equals;"633" &sol;><&sol;p>&NewLine;<h4 id&equals;"title" class&equals;"style-scope google-codelab-step"><span style&equals;"color&colon; &num;000080&semi;"><strong><span class&equals;"style-scope google-codelab-step">Use a physical device<&sol;span><&sol;strong><&sol;span><&sol;h4>&NewLine;<p>Now we will talk about how to run the application on a physical mobile device such as a phone or tablet&period;<&sol;p>&NewLine;<p>What you need&colon;<&sol;p>&NewLine;<ul>&NewLine;<li>An Android device such as a phone or tablet&period;<&sol;li>&NewLine;<li>A data cable to connect your Android device to your computer via the USB port&period;<&sol;li>&NewLine;<li>If you are using a Linux or Windows system&comma; you may need to perform additional steps to run on a hardware device&period; Check the <strong><span style&equals;"color&colon; &num;0000ff&semi;"><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"http&colon;&sol;&sol;developer&period;android&period;com&sol;tools&sol;device&period;html">Using Hardware Devices<&sol;a><&sol;span><&sol;strong> documentation&period; You may also need to install the appropriate USB driver for your device&period; For Windows-based USB drivers&comma; see <strong><span style&equals;"color&colon; &num;0000ff&semi;"><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"http&colon;&sol;&sol;developer&period;android&period;com&sol;tools&sol;extras&sol;oem-usb&period;html">OEM USB Drivers<&sol;a>&period;<&sol;span><&sol;strong><&sol;li>&NewLine;<&sol;ul>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Turn on USB debugging<&sol;strong><&sol;span><&sol;h5>&NewLine;<p>To let Android Studio communicate with your device&comma; you must turn on USB Debugging on your Android device&period; This is enabled in the <span style&equals;"color&colon; &num;008000&semi;"><strong>Developer options<&sol;strong><&sol;span> settings of your device&period;<&sol;p>&NewLine;<p>On Android 4&period;2 and higher&comma; the <strong>Developer options<&sol;strong> screen is hidden by default&period; To show developer options and enable USB Debugging&colon;<&sol;p>&NewLine;<ol>&NewLine;<li>On your device&comma; open <span style&equals;"color&colon; &num;008000&semi;"><strong>Settings<&sol;strong><&sol;span>&comma; search for<strong> <span style&equals;"color&colon; &num;008000&semi;">About phone<&sol;span><&sol;strong>&comma; click on <strong>About phone<&sol;strong>&comma; and tap <span style&equals;"color&colon; &num;008000&semi;"><strong>Build number<&sol;strong><&sol;span> seven times&period;<&sol;li>&NewLine;<li>Return to the previous screen &lpar;<strong>Settings &sol; System<&sol;strong>&rpar;&period; <span style&equals;"color&colon; &num;008000&semi;"><strong>Developer options<&sol;strong><&sol;span> appears in the list&period; Tap <strong>Developer options<&sol;strong>&period;<&sol;li>&NewLine;<li>Choose <span style&equals;"color&colon; &num;008000&semi;"><strong>USB Debugging<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ol>&NewLine;<h5><strong> <span style&equals;"color&colon; &num;0000ff&semi;">Run your app on a device<&sol;span><&sol;strong><&sol;h5>&NewLine;<p>Now you can connect your device and run the app from Android Studio&period;<&sol;p>&NewLine;<ol>&NewLine;<li>Connect your device to your development machine with a USB cable&period;<&sol;li>&NewLine;<li>Click the <span style&equals;"color&colon; &num;008000&semi;"><strong>Run<&sol;strong><&sol;span> button  in the toolbar&period; The <strong><span style&equals;"color&colon; &num;008000&semi;">Select Deployment Target<&sol;span> <&sol;strong>window opens with the list of available emulators and connected devices&period;<&sol;li>&NewLine;<li>Select your device&comma; and click <span style&equals;"color&colon; &num;008000&semi;"><strong>OK<&sol;strong><&sol;span>&period;<&sol;li>&NewLine;<&sol;ol>&NewLine;<p>Android Studio installs and runs the app on your device&period;<&sol;p>&NewLine;<p>I hope this article will help you in understanding how to get started with your Android application&period;&NewLine;

Exit mobile version