Android Learning Notes (iii)

Source: Internet
Author: User

ContentProvider Introduction

ContentProvider is a standard API for data exchange between different applications that can be implemented by providing ContentProvider when an application needs to expose its own data to other programs. Other applications can manipulate contentprovider-exposed data through contentresolver. If an application exposes its own data manipulation interface through ContentProvider, no matter whether the application is started or not, other applications can manipulate the application's internal data through the interface, including adding, deleting, modifying, and querying data.

Android:authorities Property

the defined ContentProvider class must be declared in the androidmanifest.xml before it can be used, and the authorization attribute must be added in the Declaration

Android:authorities, which is equivalent to specifying a domain name for the ContentProvider, in the Content URI content://authority/optionalpath/ The authority part of Optionalid is the value specified by the Android:authorities property. The method for the property value definition is the package name + "." + The name of the ContentProvider.

The service itself has two problems

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.

2. The service is not a new thread, so time-consuming operations should not be handled directly in the service, and time-consuming operations should open a new thread for processing.

Issues with time-consuming tasks

If you are developing this requires processing time-consuming tasks in the service module, it is generally necessary to start a new thread in the service to handle it, but you cannot start a child thread in another application component because the activity may be exited by the user, Broadcastreceiver life cycle is very short, it is possible that the child thread has not ended, the activity has been exited by the user, or the broadcastreceiver has ended, the occurrence of empty thread.

Intentservice Introduction

Intentservice can compensate for the two flaws in the service itself: Intentservice uses queues to manage the intent of requests, and whenever client code starts Intentservice through intent requests, Intentservice will add the intent to the queue and then open a new worker thread to handle the intent, and for asynchronous StartService () requests, Intentservice will sequentially process the intent in the queue, The thread guarantees that only one intent is processed at the same time. Because Intentservice uses a new worker thread to process intent requests, Intentservice does not block the main thread, so intentservice can handle time-consuming tasks on its own.

Static code block

A static block of code in a class that does not contain any method body in a format that is generally static{...}. This static block of code executes only once when the class is loaded. Static code blocks are typically used to perform initialization of class properties.

Getresources (). Getstringarray (...) Role

Getresources (). Getstringarray (r.array.setting) is a way to get an array resource in an application, that is, if you want to use an array resource defined in the application, you need to use Getresources (). Getstringarray (r.array.*), whose return value is an array.

Examples of getxxx () methods for Telephonymanager service classes

1.telephonymanager.getdeviceid ()//Get the number of the device

2.telephonymanager.getdevicesoftwareversion ()//Get the version of the system platform

3.telephonymanager.getnetworkoperator ()//Get Network operator code

4.telephonymanager.getnetworkoperatorname ()//Get network operator name

5.telephonymanager.getphonetype ()//Get mobile network type

6.telephonymanager.getcelllocation ()//Get the location of your device

7.telephonymanager.getsimcountryiso ()//acquisition of SIM card country

8.telephonymanager.getsimserialnumber ()//Get SIM card serial number

9.telephonymanager.getsimstate ()//Get SIM card status

The type of the return value is of type string.

Talk Status Listener phonestatelistener introduction

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//idle state, no active int call_state_offhook//off-hook status, at least one phone activity, this activity either calls or calls, or on hold. And no phone is ringing or waiting intcall_state_ringing//Call status, the time the phone rang or is talking to new electricity, the new phone has to wait for the period of time.

How to get SMS Manager

Smsmanager smanager= Smsmanager.getdefault (); Get the application's Smsmanager by this method

Introduction to Pendingintent Objects

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 typically passed to other application components, which are used by other applications to perform the intent that pendingintent wraps.

Broadcastreceiver Introduction

Broadcastreceiver belongs to the system-level listener, has its own process, as long as there is a matching intent is broadcast, Broadcastreceiver can be stimulated. When fired, the OnReceive () method is automatically triggered, and after the OnReceive () method is executed, the Broadcastreceiver instance is destroyed. Unlike the activity component, when the system launches the specified activity component through intent, if no suitable activity component is found, the program terminates abnormally, but when the system fires broadcastreceiver through intent, If the appropriate Broadcastreceiver component is not found, the application will not have any problems. In addition, you cannot perform time-consuming operations in OnReceive (), consider starting a service with intent to complete the operation. However, it is not possible to use the new thread to complete the time-consuming operation, because the broadcastreceiver itself has a short life cycle, and the child thread may not have finished, and Broadcastreceiver has exited.

Android Learning Notes (iii)

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.