Android: Enable or disable components

Typically, the main activity starts when you run the application. If you want another activity to start first, you can set up another start activity with an intent. However, not all components can be configured as Intents.

The content provider starts with a content resolver (ContentResolver), and the intents for the Activity and the Service need Action and URI information. The intent for the broadcast receiver requires Action information.

Activation time of the component

Component Activation time
Activity Activated by Intent
Service Activated by Intent
Broadcast Receiver Activated by Intent
Content provider Activated by ContentResolver

The component can be activated in each method. In the case of Broadcast Receivers, if you specify an appropriate intent filter in AndroidManifest.xml without explicitly calling it, it will be called and activated when the condition is met.

Activating components

component Activation
Activity Activation by passing an intent object to Context.startActivity(), Activity.startActivityForResult()
Service Enabling Context.startService() by passing intent object
Android sends intent object to Service’s onStart() method
Broadcast Receiver Enabled by passing an intent object to Context.sendBroadcast(), Context.sendOrderedBroadcast(), Context.sendStickyBroadcast()

Android deactivates an active activity for a variety of reasons, such as insufficient memory after startup. If you want to disable the component directly, you can disable it by calling each method as follows.

Deactivating the component

Component Disabled
Activity Disabled by finish().
Used finishActivity() when you want to deactivate other activities
Service Disabled with stopSelf() or Context.stopService()
Broadcast Receiver You do not need to explicitly disable it.
Activate only in response to broadcast messages
Content provider You do not need to explicitly disable it.
Activate only in response to a request from the ContentResolver.

Share This Post

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

Latest Post