The following code defines an intent that launches an activity name HelpActivity. Let’s look at some examples for defining intents in code. The constructor that defines an Intent often contains both the action and the data. The broadcast receiver determines whether it should act on the action supplied by the intent.Īn Intent( ) defines an action to be taken and the data needed for that action to occur. It does that by checking the contents of the intent. One job of the broadcast receiver is to determine whether it should handle the event. The intent service publishes that some event has occurred, and the broadcast receiver is subscribed to the event. Together intent services and broadcast receivers can be considered a “publish and subscribe” system. The broadcast receiver acts on the intent. The IntentService calls the sendBroadcast() method with an intent as a parameter.Ī BroadcastReceiver( ) receives an intent from the sendBroadcast() method. By now, you might not be surprised to learn that when the IntentService sends a broadcast, it uses an Intent as the parameter. An IntentService can send a broadcast when it completes. To package extra pieces of data along with an intent, you use the putExtra() method with the appropriate type of object you want to include.Ī service runs independently of an Activity, but often an Activity should be notified when a service completes. You can use an Intent in this way by including additional data, called extras, within the Intent. Intents can pass data between activities. With an implicit Intent, the OS presents a list of applications that can handle the task. A specific Intent is known as an explicit Intent and a less-specific Intent is known as an implicit Intent. An Intent can be specific, such as a request for a specific activity to be launched, or an Intent can be less specific and request that any activity that matches certain criteria be launched. One job of the Android OS is to associate intents with actions. When the startActivity() method is called with the intent parameter, the Android system matches the intent action with the appropriate activity on the Android system. When you want to start an Activity, you must create an Intent that specifies that Activity. An Intent contains all the information needed by the Android OS to start a task. An Intent( ) is used to make a request to the Android operating system.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |