안드로이드의 주요한 기능은 하나의 Application이 다른 Application의 elements를 사용할 수 있다는 것입니다. (단 다른 Application이 elements 사용을 허용한다는 전제조건 하에서 가능합니다.)
안드로이드 Application은 single entry point를 가지고 있지 않고 필요할 때 instance를 생성하여 실행할 수 있는 주요 Components를 가지고 있습니다. (single entry point는 예를 들어서 프로그램을 실행하기 위한 main함수가 없다는 얘기라네요)
이러한 Component는 4가지의 Type을 제공되고 있는데, 이에 대해서 하나씩 살펴보기로 하겠습니다.

1. Activities
  - Activity는 Visial User Interface를 표현합니다.
  - 각 Activity에 대해서는 그려지는 Window가 주어지게 되며, 이 Window의 visual한 content는 View Class에서 파생되는 다양한 view Object들이 제공됩니다. (button, TextView 등)
  - WIPI에서의 Card 또는 J2ME의 Canvas를 생각해 보면 쉬울 듯...
2. Services
  - Service는 Visual User Interface가 아닌 Background에서 실행됩니다.
  - 내 생각에는 기존 WIPI에서 Thread 같은것을 구현하여 Network 접속 등을 처리했을 경우와 유사한 것 같다.
3. Broadcast receivers
  - broadcast announcements를 수신하고 이에 적절한 react를 하는 Component입니다.
  - WIPI를 예로 들자면 Platform Event나 SMS Event 및 Call Event등이 해당될 것 같다.
4. Content Providers
  - 하나의 Application의 Data를 다른 Application에서 사용가능하도록 설정합니다.

위의 4가지 타입의 Component중 특정 Component에의해 제어되어야 하는 요구사항이 발생할 경우, 안드로이드는 필요하다면 Process를 실행하고, Component의 instance를 만들고 사용하게 됩니다.
아래는 각각의 경우에 따라 각 Component들에 대해 어떻게 사용이 되는지 정리합니다.

Activating components
Content Provider는 ContentResolver에 요청이 있을 경우에 활성화가 됩니다.
하니만 이외의 Activity, Service 및 Broadcast receiver의 경우는 intents라고 불리는 비동기화 메시지에 의해 활성화되게 됩니다. (Intent란 메시지 컨텐트를 보유하고 있는 Intent Object를 말합니다.)

각각의 Component에 따라 활성화 시키는 방법이 다른데 아래에 정의합니다.
  • Activity는 Intent Object를 Context.startActivity()나 Activity.startActivityForResult() method에 전달함으로써 시작됩니다.
  • Service는 Intent Object를 Context.startService() method에 전달함으로써 시작됩니다. 안드로이드는 Service의 onStart() method를 호출하고 이를 Intent Object에 전달합니다.
  • Broadcast는 Context.sendBroadcast(), Context.sendOrderedBroadcast(), Context.sendStickyBroadcast() 와 같은 method에 Intent Object를 전달함으로써 초기화될 수 있습니다.
Shutting down components
Content Provider는 ContentResolver의 요청에 응답하는 동안에만 활성화가 됩니다. Broadcast Receiver는 Broadcast message에 응답하는 동안에만 활성화가 됩니다. 따라서 이 두가지의 Component는 특별히 걱정하지 않아도 됩니다.)
하지만 Activity나 Service의 경우는 별도의 method를 제공하여 shut down할 수 있도록 합니다.
  • Activity는 finish()를 호출하여 shut down할 수 있습니다. 또한 하나의 Activity가 다른 Activity(물론 자신이 실행한 Activity입니다.)를 finishActivity()를 호출하여 shut down할 수도 있습니다.
  • Service는 stopSelf()나 Context.stopService() method를 호출하여 shut down할 수 있습니다.
manifest File
manifest는 Application의 Component에 대해 안드로이드에 정보를 제공한다.
아래와 같은 형식으로 XML로 구성되어 있으며 각각의 Component 타입에 따라서 하단의 bold 부분을 변경해 주면 된다.
<?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
    <application . . . >
        <activity android:name="com.example.project.FreneticActivity"
                  android:icon="@drawable/small_pic.png"
                  android:label="@string/freneticLabel"
                  . . .  >
        </activity>
        . . .
    </application>
</manifest>

Activity, Service, Content Provoder의 경우 manifest에 등록되지 않으면 실행할 수 없지만, Broadcasr receiver의 경우는 코드 안에서 동적으로 생성이 가능하며 Context.resisterReceiver()를 통해 System에 등록이 가능하다.






 
Posted by 피의복수
BLOG main image
일에 필요한 자료 by 피의복수

카테고리

분류 전체보기 (40)
프로그램이야기 (38)
끄적끄적 (1)
취미 (0)
서비스이야기 (1)
빅데이터 (0)

최근에 올라온 글