Lab4 #1 Create New Project

Create the First App


Like any programming, we begin with a simple Hello World example


Step 1: Create a new project



Step 3: Choose Empty Activity

Step 4: Click Finish























Step 5: Rebuild Project















Step 6: Run the App













Step 6B: If you do not have a Android Virtual device (AVD)
You need to click Create New Virtual Device

Step 7: Running














Step 8: You should see your First Hello World App



Now Let's take a look at a the file structure, java file, layout file and manifest file


Layout File activity_main.xml (Design)


The Layout File


The activity_main.xml is a layout file available in res/layout directory, that is referenced by your application when building its interface. You will modify this file very frequently to change the layout of your application. For your "Hello World!" application, this file will have following content related to default layout −

click on the Design Tab and you will see the layout
as shown below:














Layout File activity_main.xml(Text)
click on the Text Tab and you will see the XML content














Java file : MainActivity.java
This contains the .java source files for your project. By default, it includes an MainActivity.java source file having an activity class that runs when your app is launched using the app icon.



















AndroidManifest.xml file
Every app project must have an AndroidManifest.xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

The manifest file is required to declare the permissions that the app needs in order to access protected parts of the system or other apps. It also declares any permissions that other apps must have if they want to access content from this app

Example:

<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.CAMERA" />
AndroidManifest.xml

This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.









Look at AndroidManifest.xml file
<action android:name="android.intent.action.MAIN" />

means .MainActivity will be the first/ main page and be shown when you run the app
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="lab.mdad.myfirstapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>





Build.gradle

This is an auto generated file which contains compileSdkVersion, buildToolsVersion, applicationId, minSdkVersion, targetSdkVersion, versionCode and versionName

No comments:

Post a Comment

Note: only a member of this blog may post a comment.