Hello Android!! 튜토리얼 따라하기!! 1탄

2010. 2. 2. 20:20OS/Android

Eclipse 세팅까지 끝낸 지금... 곧바로 실행 모드로 돌입한다.

처음 실행 해본 결과.. 너무 느리다!!!
주의 해야 할 점은 , 최초 실행은 너무 느리기 때문에, 이후 에뮬창은 닫지 말고 지속하기를 권장 합니다.

튜토리얼을 우선 마스터를 해서, 우리 안드로이드와 친하게 지내보기로 했다.

New Android Project  선택  Project 이름을 HelloAndroid로 한다.

Build Target 은 Android 2.1 로 맞춰서 진행 한다.
Application name : Hello, Android(This is the human-readable title for your application — the name that will appear on the Android device.)
Package name : com.example.helloandroid (This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.

Your package name must be unique across all packages installed on the Android system; for this reason, it's very important to use a standard domain-style package for your applications. The example above uses the "com.example" namespace, which is a namespace reserved for example documentation — when you develop your own applications, you should use a namespace that's appropriate to your organization or entity.)
Create Activity : HelloAndroid(This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.)
Min SDK Version : 7 (This value specifies the minimum API Level required by your application. If the API Level entered here matches the API Level provided by one of the available targets, then that Build Target will be automatically selected (in this case, entering "2" as the API Level will select the Android 1.1 target). With each new version of the Android system image and Android SDK, there have likely been additions or changes made to the APIs. When this occurs, a new API Level is assigned to the system image to regulate which applications are allowed to be run. If an application requires an API Level that is higher than the level supported by the device, then the application will not be installed.)


기본으로 생성된 JAVA 파일에는 Activity를 상속받은 클래스가 최초로 생성이 되어 있다.
"Notice that the class is based on the Activity class"

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.main);
       TextView tv = new TextView(this);
       tv
.setText("Hello, Android");
       setContentView
(tv);

    }
}

그리고 그냥 finish 끝!!
그리고 실행!! -> Run As 는 Android Application 으로 ...

헐 실행이 최초에 자동으로 되지 않는 어처구니없는...
제일 먼제 Create an AVD 하라고 나온다.
아마도 AVD Manager 가 있는 상태에서 List of existing Android Virtual Devices : 가 없을 것이다.
사실, AVD 에 대한 프로그램을 실행 하였다고 하여도, 각가의 AVD를 생성해주지 않으면, 작동이 안되는것은 당연지사 일듯!

그래 New.. 해서 하나 생성해주자!.
 이클립스에서도 Android SDK and AVD Manager 로 쉽게 실행 할수 있으나,

 도스 창에서 아래 와 같은 명령어로도 실행이 가능하군

android create avd --target 7 --name my_avd

이클립스 없이 실행 하는 명령어.

android create project \ 
   
--package com.android.helloandroid \ 
   
--activity HelloAndroid \  
   
--target 2 \ 
   
--path <path-to-your-project>/HelloAndroid 



 새롭게 진행할 부분은 Construct the UI 부분이다.
 
package com.android.helloandroid; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 
 
public class HelloAndroid extends Activity { 
   
/** Called when the activity is first created. */ 
   
@Override 
   
public void onCreate(Bundle savedInstanceState) { 
       
super.onCreate(savedInstanceState); 
       
TextView tv = new TextView(this); 
       tv
.setText("Hello, Android"); 
       setContentView
(tv);
 
   
} 
}

이클립스로 작업 할때에 팁을 하나 줬는데, ctrl + shift + O 키를 누르면, import 구문이 자동 생성이 되는 것을 알아 냈다. 우하핫

Run the Application
Upgrade the UI to an XML Layout
Debug Your Project

아무튼 실행이 잘 되면,
간단하게 생성된 프로젝트에 대한 공부를 해봅시다.
 src :  사용자생성 소스
=>HelloAndroid.java : 기본으로 지정해주었던 Activity 클래스
gen : AVD 자동생성 소스
=>R.java : 그림 ,레이아웃등 다양한 Resource를 코드에서 접근 할 수 있도록 함.
      (리소스 파일에서 생성되는 클래스로 항상 자동으로 생성되며 직접 수정을 해서는 안됩니다.)
res : 리소스
=>Drawable (hdpi , ldpi , mdpi ) : 어플리케이션 내에서 사용될 그림 파일들
=>Layout  : Activity의 화면 구성 정보를 담고 있는 xml파일들
=>Values  : 문자열, 배열, 색, 스타일등 다양한 부가 정보들.
  (그외에 Animation, XML, Style, 원시 리소스등 총 7가지가  있다고 한다)
Android Library : 안드로이드 SDK 사용을 위해 포함된 라이브러리
AndroidManifest.xml : 어플리케이션과 구성과 관련된 모든 정보를 담고 있는 파일. 어플리케이션 작성에서 가장 중요한 역할을 하는 파일입니다. 어플리케이션과 Activity의 다양한 설정, 사용권한, 연관된 라이브러리 등 다양한 정보를 포함합니다.

리소스 부분은 application이 빌드될 때 가능한 한 효율적으로 컴파일되어 application package에 포함된다. 리소스는 각각에 대한 레퍼런스를 담고 있는 R 클래스 파일을 생성한다.
 이는 디자인 타임 문법 검사의 이점과 더불어 코드에서 리소스를 참조할 수 있도록 해준다.
리소스도 별도로 정리를 해야 할것 같다.


안드로이드 책을 보지 않고 우선 인터넷에 떠돌아 다니는 글을 대충 참고하여 여기까지는 진행 했습니다.
이제 차근차근이 진행을 해봐야 겠죠

안드로이드 펍에서 발표한 자료가 돌아다니길래... 이건 첨부 합니다 ..
근데.. 첨부한 파일이 문제가 될 시에는 삭제해도록 할께용


오늘의 목적은 우선 안드로이드 실행이 주 목적인 셈이니, 달성했다.
이후부터 세부적인 부분부터 파헤쳐 볼 예정이다. 오늘은 여기까지만 진행 할꺼랍니다.

'OS > Android' 카테고리의 다른 글

Designing for Performance (성능의 최적화)  (0) 2010.02.03
안드로이드 개발 환경 설정  (1) 2010.02.02