앞서 안드로이드에는 4대 구성요소(Component)가 존재하고, 각 구성요소가 앱의 진입지점이 될 수 있다는 것을 알았다. 그렇다면 각 컴포넌트에 진입하는 방법에는 무엇이 있을까?
An asynchronous message called an intent activates three of the four component types: activities, services, and broadcast receivers.
Intents bind individual components to each other at runtime. You can think of them as the messengers that request an action from other components, whether the component belongs to your app or another.
Intent 라는 일종의 메신저를 통해 액션을 전달함으로서 4대 컴포넌트 중 3가지, 액티비티, 서비스, 브로드캐스트 리시버를 실행시킬 수 있다.
Unlike activities, services, and broadcast receivers, content providers are activated when targeted by a request from a
ContentResolver. The content resolver handles all direct transactions with the content provider, and the component performing transactions with the provider calls methods on theContentResolverobject. This leaves a layer of abstraction for security reasons between the content provider and the component requesting information.
반면에 컨텐트 프로바이더는 컨텐트 리솔버라는 오브젝트를 통해 요청을 받음으로서 활성화된다.
There are separate methods for activating each type of component:
- You can start an activity or give it something new to do by passing an Intent to
startActivity()or, when you want the activity to return a result,startActivityForResult().- On Android 5.0 (API level 21) and higher, you can use the JobScheduler class to schedule actions. For earlier Android versions, you can start a service or give new instructions to an ongoing service by passing an Intent to
startService(). You can bind to the service by passing an Intent tobindService().- You can initiate a broadcast by passing an Intent to methods such as
sendBroadcast()orsendOrderedBroadcast().- You can perform a query to a content provider by calling
query()on a ContentResolver.
Intent를 매개변수로 받는 startActivity() startActivityForResult() startService() bindService() sendBroadcast() sendOrderedBroadcast()등을 통해 액티비티, 서비스, 브로드캐스트 리시버를 활성화 시킬 수 있고, 컨텐트 프로바이더는 컨텐트 리솔버의 query() 를 통해 활성화 할 수 있다.