Android Learning notes (iii)

Source: Internet
Author: User
<span id="Label3"></p><p><p><strong>ContentProvider Brief Introduction</strong></p></p><p><p>ContentProvider is the standard API for data exchange between different applications, when an application needs to expose its own data to other Programs. The application can be implemented by providing contentprovider, and other applications can manipulate contentprovider exposed data through Contentresolver. Suppose an application exposes its own data manipulation interface through contentprovider, regardless of whether the application is started or Not. Other applications are able to manipulate the Application's internal data through this Interface. Includes adding, deleting, changing, querying Data.</p></p><p><p></p></p><p><p><strong>Android:authorities Property</strong></p></p><p><p><strong></strong> the defined ContentProvider class must be declared in androidmanifest.xml, and the authorization attribute must be added to the Declaration.</p></p><p><p>Android:authorities. Equivalent to specifying a domain name for the contentprovider, the authority part of Content://authority/optionalpath/optionalid in the Content URI is android: The value specified by the authorities Property.</p></p><p><p>The method for the property value definition is the package name + "." + The name of the Contentprovider.</p></p><p><p><strong>The service itself has two problems</strong></p></p><p><p>1. The service does not start a separate process specifically, and the service is in the same process as the application in which it Resides.</p></p><p><p></p></p><p><p>2. The service is not a new thread. therefore, time-consuming operations should not be handled directly in the Service. The time-consuming operation should open a new thread to Handle.</p></p><p><p><strong>Issues with time-consuming tasks</strong></p></p><p><p>Suppose that it is necessary to process the time-consuming tasks in the service module, usually by starting a new thread in the service, but not to start the child threads in other application components, because the activity may be exited by the user, The life cycle of the broadcastreceiver is very short. It is very likely that a child thread has not ended. The activity has been exited by the user, or the broadcastreceiver has ended and a null thread has Occurred.</p></p><p><p><strong>Intentservice Brief Introduction</strong></p></p><p><p>Intentservice can compensate for the two flaws in the service Itself: Intentservice uses queues to manage the intent of requests whenever the client code initiates Intentservice through intent Requests. Intentservice will add the intent queue, and then open a new worker thread to handle the intent, for asynchronous StartService () Requests. Intentservice sequentially processes the intent in the queue, which guarantees that only one intent is processed at the same time.</p></p><p><p>Because Intentservice uses the new worker thread to process intent requests, Intentservice does not block the main thread, so intentservice can handle time-consuming tasks on its own.</p></p><p><p><strong>Static code block</strong></p></p><p><p>That is, the class does not include static blocks of code, regardless of the method body, and is generally formatted as static{...}. Such static blocks of code run only when the class is loaded and run only Once.</p></p><p><p>Static code blocks are typically used to run initialization of class Properties.</p></p><p><p><strong>Getresources (). Getstringarray (...) Role</strong></p></p><p><p>Getresources (). Getstringarray (r.array.setting) is the method that gets the array resources in the Application. That is, if you want to use the array resources defined in the application, you need to use getresources (). Getstringarray (r.array.*), whose return value is an array.</p></p><p><p><strong>Examples of getxxx () methods for Telephonymanager service classes</strong></p></p><p><p>1.telephonymanager.getdeviceid ()//get The number of the device</p></p><p><p>2.telephonymanager.getdevicesoftwareversion ()//get The version number of the system platform</p></p><p><p>3.telephonymanager.getnetworkoperator ()//get Network Operator Code</p></p><p><p>4.telephonymanager.getnetworkoperatorname ()//get Network operator name</p></p><p><p>5.telephonymanager.getphonetype ()//get Mobile network type</p></p><p><p>6.telephonymanager.getcelllocation ()//get the location of your device</p></p><p><p>7.telephonymanager.getsimcountryiso ()//acquisition of SIM card country</p></p><p><p>8.telephonymanager.getsimserialnumber ()//get SIM card serial number</p></p><p><p>9.telephonymanager.getsimstate ()//get SIM card status</p></p><p><p>The type of the return value is of type String.</p></p><p><p><strong>Call Status Listener Phonestatelistener Brief introduction</strong></p></p><p><p>Phonestatelistener is a call state listener that must implement the Oncallstatechanged (intstate, String Number) method when defining the Listener. Main static constants for call State: int Call_state_idle//spare state, no matter what activity int Call_state_offhook//off-hook State. There is at least one phone activity, which is either a call or a call, or on HOLD. And no phone is ringing or waiting Intcall_state_ringing//call status. The time when the phone rang or was talking to new electricity, the new call had to Wait.</p></p><p><p><strong>How to get SMS Manager</strong></p></p><p><p>Smsmanager smanager= Smsmanager.getdefault (); Get the Application's Smsmanager by this method</p></p><p><p><strong>Pendingintent Object Brief Introduction</strong></p></p><p><p>The Pendingintent object is a wrapper over the intent, typically by calling Pendingintent's getactivity (), getService (), getbroadcastreceiver () static method to get the Pendingintent Object. Unlike the intent Object. Pendingintent is generally passed on to other application components, which are used by other applications to run the intent packaged by Pendingintent.</p></p><p><p></p></p><p><p><strong>Broadcastreceiver Brief Introduction</strong></p></p><p><p>Broadcastreceiver belongs to a system-level listener, has its own process, and only the intent that match it is broadcast. Broadcastreceiver can be Stimulated.</p></p><p><p>When it is fired, it automatically triggers its onreceive () method, after the OnReceive () method has finished Running. Instances of Broadcastreceiver will be Destroyed. Unlike the activity component, when the system launches the specified activity component through intent, it is assumed that the appropriate activity component is not found, causing the program to terminate Abnormally. however, when the system fires broadcastreceiver through intent, it is assumed that no suitable broadcastreceiver component can be found, and no matter what the application Does. In addition, you cannot run time-consuming operations in OnReceive (), and you can consider starting a service with intent to complete the Operation. however, You cannot use the new thread to complete the time-consuming Operation. Since the life cycle of the broadcastreceiver itself is very short, it is possible that the child thread is not over and Broadcastreceiver has Exited.</p></p> <p><p>Android Learning notes (iii)</p></p></span>

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.