Android Learning note 7 components communication and broadcast messages (ii)

Source: Internet
Author: User

Intent implicit startup activity

The benefit of an implicit startup is that it is not necessary to indicate which other component needs to be started in the first component, which is determined by the Android system, which facilitates reduce the coupling between components。 Choosing to implicitly start the activity,android system resolves the intent when the program runs and matches intent and components according to certain rules so that the action, data, and category on the intent coincide with the target activity. The matching component can be activity on the program itself, or it can be an activity built into the Android system, or it can be an activity provided by a third-party application. Therefore, this approach emphasizes the reusability of Android components. Because it is an implicit call, in this case the componentname value of intent is null. At this point, the 1th parameter of the intent constructor is the action (action) that intent needs to perform, and the Android system supports common Action String ConstantsRefer to the table below. The 2nd parameter is a URI that represents the data to be passed.

ACT Ion_view The most commonly used action, the URI of the data transmitted, according to the URI protocol part of the best way to initiate the corresponding activity for processing . For http:address will open the browser to view, for tel:address will open the dial-up interface and call the designated phone number

Action_dial Open the built-in dial-up interface to display the phone number provided in the URI

Action_call Open the Dial screen and Dial the phone, using the number part of the URI as the telephone number

Action_answer Open the activity to answer the phone, default to Android's built-in dial-up interface

Action_delete open an activity to delete the provided data

Action_edit open an activity to edit the data provided

Action_insert Open an activity to insert a new item at the current location where the data is provided

Action_web_search open an activity to make a WEB search of the data provided

Action_pick start a child activity, select an item from the list of available data

Action_search start an activity to perform a search action

Action_sendto initiates an activity to send a message to the data-supplied contact person

Action_send start a activity that can send data

My practice is to invoke the intent constructor with parameters Action_call and tel:13278891040 and send it to start the dial-up interface and call.

The code that needs to be changed here is the construction method of the intent in the OnCreate () method

 Public void OnClick (View v) {        /// The first parameter is action, the second argument is URI        new              Intent ( Intent.action_call,uri.parse ("tel:13278891040"));        StartActivity (intent);}

But after running this, there was an error when clicking the button on Mainactivity (on the phone). Logcat Display Fatal Exception:main

Baidu did not find a bit more formal explanation, but their mistakes are basically in androidmanifest.xml inside, and later in a blog saw said must "add users-permission in Androidmanifest, and declare the use of rights: <uses-permission android:name= "Android.permission.CALL_PHONE"/> This is because the phone calls belong to the bottom of the service, and user privacy and call fees, etc., so The program must obtain the relevant permissions. “

Add later found no more error. You can just call out the phone.


Android Learning note 7 components communication and broadcast messages (b)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.