Tuesday, November 10, 2015

101 Android Studio Create New Empty Project


.

101 Android Studio Create New Empty Project
This tutorial is a variation of the official tutorial at http://developer.android.com/training/basics/firstapp/creating-project.html .
This tutorial was done with Android Studio 1.4.
1) In Android Studio, create a new project.
File/New/Project...
1.1) Give a name to the project, ie MyEmptyProject1
1.2) Select target device.
1.3) Select Empty Activity.
For a layman, an activity looks like a screen or a page. And that is all about it.
However an activity technically contains more than that for example API for camera, storage, network connectivity etc.
So it is more appropriate to call it as “Activity” instead of a “Page”.
1.4) Give a name to Activity and its Layout.
(Just accept default).
Few programming concepts that you learn here…
“Main” name is usually given to the codes that will be executed first when your application run.
Most programming language nowadays separate the programming codes by their roles. Android also promotes code separation.
Codes that define business logic (sometimes called CONTROLLERS) is saved as Activity (in Java Language)
Codes that define the look of the apps (sometimes called VIEWS) is saved as Layout (in XML Language).
You will see more examples of this as you progress.
Click Finish and wait for the code generation process.
2) Important files
Android Studio generated, amongst all,  four important files.
2.1) activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".MainActivity">
   <TextView android:text="Hello World!" android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
</RelativeLayout>
2.2) MainActivity.java
package com.notarazi.myemptyproject1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
   }
}
2.3) AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.notarazi.myemptyproject1" >
   <application
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       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>
2.4) Build.Gradle (Module:App)
apply plugin'com.android.application'
android {
   compileSdkVersion 23
   buildToolsVersion "23.0.1"
   defaultConfig {
       applicationId "com.notarazi.myemptyproject1"
       minSdkVersion 14
       targetSdkVersion 23
       versionCode 1
       versionName "1.0"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       }
   }
}
dependencies {
   compile fileTree(dir'libs'include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.1.0'
}
Android Studio generated many codes and files.
In fact, there were too much codes generated only to produce “Hello World” output.
DO NOT TRY TO MEMORIZE CODES.
Instead,
TRY...
TO RECOGNIZE WHERE IMPORTANT CODES ARE LOCATED
AND...
UNDERSTAND WHAT THEY DO.
In the end,
INQUISITION and CURIOSITY is the ultimate motivation for developers.
3) Outcome
DOWNLOAD

.

No comments:

Post a Comment