본문 바로가기

안드로이드 기초

mobile/android by 낼스 2020. 3. 16.

# Activity   ┐
# Service    ┤ Intent를 통해 동작할 수 있음. ( Boot시 Manifest 로딩해서 해석함 : 그러므로 부하없음 )
# Recevie    ┘
# Provider  ( Boot시 Constructer 호출됨 )

# Intent : Componet 실행을 위해 System에 띄우는 메시지.

# BroadcastRecevier - Event Model로 수행되는 Component
  - Life 사이클 없음
  - onReceive <- 10초 Rule

# data 영속화
  - file read/write
  - SharedPreference : key-value
  - SQLite : open source > www.sqlite.org
     ( Embeded Device의 데이터 자원을 저장하기위해 )
    <목적> 안정성/경량/이용편의성(R-DBMS : ANSI)
        # 설정 자동화 기능
            1. 설정 자동화 XML 파일 생성
                
                
                    .                          ┌─ 화면 UI
                    .                    ┌─────┴─ 설정내용자동저장
                    R.xml.a ─────────────┘

# SQLiteDataBase Class
   - execSQL  : return boolean?
   - rawQuery : return Cursor
   - insert : argument : [ tablename, ContentValues : key(column name) -value] - sql mapper
   - update : sql mapper
   - delete : sql mapper
   - query  : sql mapper

  # SQLiteOpenHelper - 추상클래스
    - onCreate() : db 초기화
    - onUpgrade(): db 스키마 update

  # DBAdapter

# 질문
  1. 런처는 컴포넌트입니까? --> Home App?
  2. BroadcastRecevier :  service와의 부하차이는?
  3.

# sqlite에서 알아둘것
  - sqlite는 alter문을 지원하지 않는다. ( drop -> create )

# Android UI 프로그램
                    R.layout....
  ● Activity.setContentView("layout.");

  ● GOF Pattern - Composit Pattern 설계

  ● Document Object Model
  ▶ 객체의 계층구조
                       ┌────────┐
                       │  View  │
                       └────────┘
       ┌─────────────┐              ┌─────────────┐
       │  ViewGroup  │              │  Control    │ 단순View
       └─────────────┘              └─────────────┘
    계층구조상 자신의 하위에
        여러 View를 Add

       ┌──────────┐                             ┌──────────┐
       │  Layout  │  Add된 View의 정렬 규칙     │  Widget  │  여러 View를 합쳐 하나의 View
       └──────────┘                             └──────────┘

LinearLayout :  가로 /세로 방향
RelativeLayout :
TableLayout :
FrameLayout :

# View - Composite Pattern에의한 계층구조 Model
    ● hierarchy Event Model : 원론적 Event처리 - key , touch ::> onKeyDown, onKeyUp(), onTouchEvent()[DOWN,UP,MOVE];
                                                --> home,menu, back, search ::> home,power key  제어안됨.
    ● delegation Event Model : OOP적으로 재해석
        ( View Event :  Observer Pattern. )

            Event발생 객체                      Event 처리내용 객체
        ┌───────────────┐        Listener  ┌───────────────┐
        │  EventSource  │ ------------>    │  EventHandle  │
        └───────────────┘                  └───────────────┘

        bt.setOnXXXXListener();

    # 구현예)
        Class A implements OnClickListner {
            onClick(){
            }
        }

# 항목 나열성격 View
                                    Adapter                                         Activity
    ListView                                                ◀ data
        ┌───────────────┐       Adapter Pattern
        ├───────────────┤       동일 interface로
        ├───────────────┤       여러 View에 적용하겠다.
        ├───────────────┤                                   ◀ layout정보
        └───────────────┘                                      한가지 항목
    Spinner

    AutoCompleteTextView

    GridView

    ArrayAdapter    : 항목당 DATA 1개
    SimpleAdapter   : 항목당 DATA n개
    CursorAdapter   : db select cursor


    class A extends ArrayAdpater {

        // override
        getView() {
        }

    }

    성능이슈 -> layout초기화
             -> findViewById();
    유저 Interactive 행동에의한 화면 출력

# A1 
  A2
    
    
                        
    
    

# Intent i = new Intent(this, A1.class ); // 명시적 Intent

# 암묵적 Intent. 는 직접 Actvity를 지정하지 않고,
   action 또는 category 또는 Data를 필터로 하여 Activity를 접근하는 방식을 제공한다.
    Intent i = new Intent();
    i.setAction();
    i.setCategory();
    i.setData(); // Uri.parsse(url);

    StartActivity(i);

# ContentProvider
            authorities="AAAA"

    getConentResolver().insert (Uri.parse("content://AAAA"),....);
                       .update
                       .delete
                       .query

# 컨텐츠 제공에대한 권한
    
        ▲ ▼
        ▲ ▼
        ▲ ▼
        ▲ ▼
    

# Activity event 5초 rule.. ( 5초이상일경우 이벤트 무효화 )
    # Network
        - http
        - tcp/ip

    # Thread program
        - main(UI)Thread


# 채팅 구현 방법
    - 폴링 : 클라이언트가 서버에 접근해서 데이터를 가져온다.
    - 소켓
    - 서버push

# Activity의 LifeCycle
                onCreate();                 setContentView(); , addContentView(); [  SurfaceView ]  ---->
                onRestoreInstanceState();  : 데이터 복구 구현                                       ---->
    ┌────────▶ onStart();
    ├    ┌──▶  onResume()                 : 활성상태, 화면상위(onTop), UserEvent가능
    ├    ├                                    onResume에서 화면 출력이 실제적으로 이루어진다.
onRestart├      onSaveInstanceState();     : 유실될 가능성이있는 데이터 저장                        ----------> Bundle(Map-key-value) -- file
    ├    ├      onPause();                 : Pause상태, 화면 상단 , UserEvent불가능
    ├    └───── onStop()                   : 비활성상태, 화면 상단 X
    └────────── onDestory                  : ● 명시적 - user명령 : backbutton
                                                      - code명령 : finish
                                             ● System에서 알아서 - 메모리 부족
                                                                 - resource 재할당 (화면 회전)
    1. 번들 - FILE I/O
        번들을 이용한 데이터 저장 처리는 데이터 저장 형에 제한이있을 수 있다. 하지만 왠만한 데이터는 저장된다..

    2. nonconfiguration instance : MEMBORY I/O

# menu

    // menu 설정... menu 설정을 위해서 자동호출.. 매개변수인 Menu가 개념상  menu bar
    // Menu 에 add
    // onCreateOptionMenu  : Activity 초기화 시 딱 한번 호촐.. 고정 메뉴시 이용.
    // onPrepareOptionMenu : menu 가 화면에 나올 시점마다 반복 호출...
    // onCreateContextMenu : ContextMenu : 다른 메뉴는 메뉴 버튼을 눌럿을때 나오지만
    // Context 메뉴는 특정 view를 오래 놀렀을때 팝업 다이얼로그 스타일로 뜨는 메뉴..
                                                                                    ┌────────────────────┐
                                                                                    │  Boot Complete     │
                                                                                    └────────────────────┘
                                                                                        ▼     ▼   ▼
                                                                                    ┌────────────────────┐
                                                                                    │  StartupReceiver   │
                                                                                    └────────────────────┘
                                                                                           ▼    ▼    ▼
┌───────────────┐    ┌───────────────┐    ┌───────────────┐    ┌───────────────┐        ┌───────────────┐  ▶ ┌────────────────────┐
│     Intro     │ ▶ │  CheckInvite  │ ▶ │      Main     │ ▶ │     Chat      │        │    Service    │     │ ChatServer(socket) │
└──────┬────────┘    └───────────────┘    └────────┬──────┘    └───────▲───────┘        └───────────────┘  ◀ └────────────────────┘
       │                                           │                   └──────────────────┐  ▼       ▲
       └───────────────┐       ┌───────────────────┼──────────────────────┐               ▼  ▼       ▲
                       ▼       ▼                   ▼                      ▼             ┌────────────────────┐
                     ┌──────────────────┐    ┌───────────────┐    ┌───────────────┐     │NotificationReceiver│
                     │ SettingPreference│    │    MyStatus   │    │     Invite    │     └────────────────────┘
                     └──────────────────┘    └───────────────┘    └───────────────┘

        Activity             >> ┌───────────────┐ <<    Activity
Intent  startSevice          >> │    service    │ <<    bindService
        [내부 Receiver구현]  >> └───────────────┘ <<
        stopService          >>                   <<    unbindService

        접속빈도 낮을경우                       접속빈도 높을경우.
       결합관계가발생안함.                      객체가 빈번하게 생성소멸되지 않는다.
                                                bind한 연결 서비스가죽으면 같이 소멸한다.

startService    Service                 bindService
                    onCreate()          onBind()
                    onStart()           unBindService();
stopService         onDestory()         unBind()

# handle device의 특성상 connection이 유실될 가능성때문에.
    connection 유지를 Thread로 구성.
     Thread [ connection ]
        write
     Thread [ read ]


# 프로바이더
    LocationManager ( GPS )
    NetWork         ( 3G  )
    Wifi

댓글