Monday, December 8, 2014

103-ADT18-Create An Android Project

---
103-ADT18-Create An Android Project
An Android project contains all the files that comprise the source code for your Android app. The Android SDK tools make it easy to start a new Android project with a set of default project directories and files.
This lesson shows how to create a new project either using  Android Developer Toolkit(ADT) API Version 18.

1) Click Menu File/New/Android Application Project




2) New Android Application options

Fill up the form based on the guide at http://developer.android.com/training/basics/firstapp/creating-project.html and then click Next.
The explanation as stated on the above website:
  • Application Name is the app name that appears to users. For this project, use "My First App."
  • Project Name is the name of your project directory and the name visible in Eclipse.
  • Package Name is the package namespace for your app (following the same rules as packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. For this reason, it's generally best if you use a name that begins with the reverse domain name of your organizationor publisher entity. For this project, you can use something like "com.example.myfirstapp." However, you cannot publish your app on Google Play using the "com.example" namespace.
  • Minimum Required SDK is the lowest version of Android that your app supports, indicated using the API level. To support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature set. If any feature of your app is possible only on newer versions of Android and it's not critical to the app's core feature set, you can enable the feature only when running on the versions that support it (as discussed in Supporting Different Platform Versions). Leave this set to the default value for this project.
  • Target SDK indicates the highest version of Android (also using the API level) with which you have tested with your application.
  • As new versions of Android become available, you should test your app on the new version and update this value to match the latest API level in order to take advantage of new platform features.
  • Compile With is the platform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK. (It should be Android 4.1 or greater; if you don't have such a version available, you must install one using the SDK Manager). You can still build your app to support older versions, but setting the build target to the latest version allows you to enable new features and optimize your app for a great user experience on the latest devices.
  • Theme specifies the Android UI style to apply for your app. You can leave this alone.

3) Project Configuration.

Accept Default.
Click Next.

4) Configure Launcher Options.

Accept Default.
Click Next.

5) Create Activity Option.

Accept Default (Tick Create Activity)
Click Next.
When we choose Create Activity, ADT will perform two tasks:
1) Create a Java Class for the Activity
2) Update Android Manifest file.
AndroidManifest.xml is a powerful file in the Android platform that allows you to describe the functionality and requirements of your application to Android.

6) New Blank Activity options.

Accept Default.
Click Finish.

7) Observe Package Explorer Panel.

Check each of the files.
7.1) MainActivity.Java
A typical Java file consists of three segment of codes:
a) The package declaration (to identify the project codes)
b) The import declaration (to use the existing code libraries)
c) The class instructions (programmer instructions)
package com.example.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}
Notice the statement setContentView(R.layout.activity_main);
It tells the apps to set its view based on the layout specified in the file activity_main (which is kept in the sub folder layout of the Resource folder).
7.2) activity_main.xml
(You may need to click the tab “activity_main.xml” in order to see the source codes)
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
</RelativeLayout>
7.3) AndroidManifest.xml
(You may need to click the tab “AndroidManifest.xml” in order to see the source codes)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myfirstapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Notice that the AndroidManifest.xml actually contains the information that has been mostly entered in the project setup wizard above (Step 2 to Step 6).
---

102-ADT 18 Android Virtual Device


---
102-ADT 18-Manage Android Virtual Device
-

1) Android Virtual Device

You need to setup an Android Emulator to test your Android Apps..

2) Open AVD Manager

Click Menu Window/Android Virtual Device Manager.

3) Create a new AVD

3.1) Click "New..."
3.2) Enter the required details.
Click OK when done.
3.3) To test the machine, select the machine name and click Start… button.
4) Launch options.
4.1) Accept the default and click Launch.
4.2) The Starting progress windows pops up.
4.3) Wait for the Android emulator to load.
4.4) You have to wait for logon screen to appear.
It may take some time.
When the unlock screen appear, use your mouse to tap on the padlock icon and drag it to the right to unlock the machine.
Finally you should see the following output.
4.5) Look at the title of the window, 5554:WQVA33
5554 is the port number of the emulator that allows it to communicate with other software.
WQVA33 is the name given in Step 3.2.

5) You can leave this emulator window open while building the app.

-
---

101-Installing the Eclipse ADT 18 Bundle Win 7


---
101-Installing the Eclipse ADT 18 Bundle Win 7
Eclipse ADT 18 on Windows 7

1) Main Reference

2) Download and extract the ADT zip file.

2.1) Right-click the file, select Extract All…
2.2) Set the target path, e.g D:\ANDROID\
(Be careful not to extract to My Documents or Desktop because long file names may cause a problem to the extraction process)
2.3) Outcome.
2.4) Create a workspace folder.

3) Running ADT (Eclipse)

3.1) Locate the eclipse program.
eclipse program should be found within the folder eclipse of the ADT bundle folder.
3.2) (Optional) Create a shortcut to Start Menu.
(When the icon appears in the Taskbar, you can easily click it to run eclipse program)
3.4) Run eclipse.
3.5) Eclipse will ask you to enter the workspace path
e.g D:\ANDROID\adt-bundle-windows-x86_64-20130917\workspace
Tick the checkbox for “Use this as the default and do not ask again”.
3.6) Finally eclipse displays the Welcome Screen.
3.7) Close the Welcome Screen.
3.8) You should see the eclipse application window.

4) Checking the About Window, SDK Manager and AVD Manager

4.1) About Window
About Window tells us the version of this ADT application.
4.2) SDK Manager
SDK Manager helps us to download and install the SDK ToolsAPI Version and System Image for this ADT Application.
4.3) AVD Manager
AVD Manager helps us to setup Android Emulator in order to test Apps created by this ADT application.
---