본문 바로가기

나 어제 배웠다/Android

Android HelloAndroid

1. New

 (m) File > New > Other > Android > Android Project

 (i) 

 

2. ClassLibrary

- HelloAndroid 선택 후 마우스 오른쪽 버튼 > Preperties

- Java Build Path > Order and Export Tab

- Android 2.1 Check

- OK

 

3. 구조

 

 

+ src[source] : .java , .aidl

+ gen[generate] : R.java

+ Android 2.1 : core-android.java

+ assets[자산] : font(ttf), txt, html ...

+ res[resource] : image, xml, animation, color,  화면해상도

- drawable-hdpi(mdpi,ldpi) : png, jpg, gif (png 선호 - 투명도처리가능)

- layout : xml

- values : string.xml, colors.xml, arrays.xml

- raw : txt

 

- AndroidManifest.xml

- Application전반정보[Version,Activity, Service, Intent, Permmission..]

   ex) web.xml과 동일한 역할 함

 

4. 실행

(m) Run > Run As > Android Application

 

 

 5. 소스분석

package soo.base;

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

public class HelloAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);                           // R.java
    }
}

 

R.java

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package soo.base;

public final class R {                                              //final class 이므로 상속 안됨(수정제한자)
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;              // image 실제 주소
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}


JAVA TIP

제한자 : 클.인,변,메소드,생성자 앞에 붙어 기능

1. 수정 제한자

//final class 상속안됨

Class A{

 final int I = 10; //상수

int j = 20;

 final void method() {

 //override 안됨

 }

 void m2() {

         System.out.println(this.j);

         this.m3();

 }

 void m3() {

 }

}

2. 소유 제한자

static : 클래스 소속

- 주체 : 객체, 클래스[주체], instance(메모리상의존재) 

- 대상 : 멤버변수(=속성), 메소드

- 접근 : Class  접근 가능 , 객체 접근가능 (공유되기 때문)

   A.I; //A클래스는 i()를 소유

   new A().I;  //객체접근가능