Android-based test summary Android Basics ContentProvider (ii)
In the previous section of Android test paper summary of the Android Foundation activity (a) We speak of the activity of the basic knowledge. Have a lot of friends reflect look at the more chaotic, I went back to see, indeed very messy, not careful. Then I tidied it up again. Let everyone read the experience better!
If you have any questions during the reading process, please do not hesitate to contact us.
This chapter is the "Android beauty from 0 to the best of the Road" Android basic ContentProvider summary of Android developers interview more common ContentProvider and intent related interview questions. Hope for the vast number of Android developers, helpful.
- Android Face Test summary Android Foundation ContentProvider II
- ContentProvider Common knowledge points
ContentProvider Common knowledge points
-
ContentProvider How to implement data sharing
If you want to provide your app's data (typically more data in a database) to a third application in Android, we can only ContentProvider to achieve it. The
ContentProvider is an interface for sharing data between applications. When using, first customize a class to inherit ContentProvider, and then overwrite the methods of query, insert, UPDATE, Delete, and so on. Because it is one of the four components, it must be registered in the Androidmanifest file.
Share your data in the form of a URI
different program data under the Android system by default is not shared access needs to implement a class to inherit ContentProvider
< Code class= "Hljs java" >public class personcontentprovider extends contentprovider { public boolean oncreate () {} query (URI, string[], String, string[], string) Insert (URI, contentvalues) update (URI, Contentvalues, String, string[ ]) Delete (Uri, String, string[])}
"'
Third parties can access the Provider through Contentresolver.2.**android Data Storage Method * * A. File storage B. Sharedpreference storage c. contentprovider storage D. sqlitedatabase storage E. Networked storage about Contentprov Ider the basic knowledge points, this chapter is the first to summarize this. We hope to help you.3.* * Why use ContentProvider? What is the difference between it and the SQL implementation? * * ContentProvider block the details of the data storage, the internal implementation of the user is completely transparent, the user only need to care about the operation of the data URI can be, ContentProvider can be shared between different apps. SQL also has a method of adding and pruning, but SQL can only query the database under this application. And ContentProvider can also go to delete and change the local file. XML file reading, and so on.4.* * Talk about the relationship between ContentProvider, Contentresolver and Contentobserver * * A. ContentProvider content provider for external Data b. CONTENTRESOLVER.N Otifychange (URI) emits a message c. contentresolver content resolver, used to obtain data provided by the content provider D. Contentobserver content Listener, can listen to the change status of the data E. contentresolve R.registercontentobserver () listens for messages.5.**uri Introduction * * For each resource of the system give it a name, say the call log.1), each contentprovider has a common URI, which is used to represent the data provided by this contentprovider.2), the ContentProvider provided by Android are stored in the Android.provider package. It is divided into a,b,c,d4Sections: A: Standard prefix, used to describe a content provider control of these data, can not be changed;"content://"The identity of the B:uri, which uniquely identifies the contentprovider, can be found by an external caller based on this identity. It defines which content provider is providing this data. For third-party applications, to guarantee the uniqueness of the URI identity, it must be a complete, lowercase class name. This identity is described in the authorities attribute of the element: Typically, the package that defines the ContentProvider. The name of the class C: path, which is the name of the table in the database you want to manipulate, or you can define it yourself, Remember to keep it consistent when you use it;"Content://com.bing.provider.myprovider/tablename"D: If the URI contains an ID that represents the record that needs to be fetched, then the data corresponding to that ID is returned, and if there is no ID, it returns all;"content://com.bing.provider.myprovider/tablename/#"#表示数据id.6.* * How do I access the database under the asserts resource directory? * * Copy Database db to the/data/data/packagename/databases/directory and access it directly. # # Intent Detailed1.**android Intent Use * * What are the three main components--activity, service, and broadcast receiver activated? Answer: Intent is a runtime-bound message mechanism, and the three components--activity, service, and broadcast receiver are all activated by the message, which is intent. A intent object consists of six attributes, please list these six attributes each. Answer: The component name (Component name), action, data, category, additional information (Extra), and flags (flags). Answer: In an Android application, it is mainly composed of some components (activity,service,contentprovider,etc.) In the communication between these components, the intent assists the completion. As some people on the internet said, intent is responsible for the operation of the application in the action, the action involved in data, additional data description, Android according to the description of this intent, is responsible for finding the corresponding component, the intent passed to the calling component, and complete the call of the component. Intent is where the decoupling between the caller and the callee is implemented. In intent delivery process, to find the target consumer (another activity,intentreceiver or service), that is, the intent responder, there are two ways to match:1, explicit: Pseudo Code "" PublicTestb extents Activity {...}; Public class Test extends Activity {...... Public void switchactivity() {Intent i =NewIntent (Test. This, Testb.class); This. startactivity (i); } }
The code is straightforward, and the switchactivity () function is executed, and immediately jumps to the activity named Testb.
2. Implicit intent:
Implicit matching, first to match several values of intent: Action, Category, data/type,component
If you fill in the componet is the Test.class in the example above) this forms a display match. So this section only tells the first few matches. The matching rule is the maximum matching rule,
1. If you fill in the action, If there is an activity in the Intentfilter segment of a program that contains the same action as defined in the manifest.xml, then this intent matches the target action, and if no type is defined in the filter segment, Category, then the activity is matched. But if you have more than two programs in your phone, a dialog box will pop up to show you the message.
The value of action has a lot of pre-defined in Android, and if you want to go directly to your own defined intent receiver, you can add a custom action value to the recipient's Intentfilter (and set the category value to " Android.intent.category.DEFAULT "), set the action in your intent to intent, and you can jump directly to your own intent receiver. Because this action is unique in the system.
2, Data/type, you can use the URI as data, such as URI uri = Uri.parse (http://www.google.com);
Intent i = new Intent (Intent.action_view,uri); During the Intent distribution of the cell phone, the data type is judged according to the http://www.google.com scheme.
The brower of the handset can match it, in the intenfilter of Brower Manifest.xml first have Action_view Action, also can handle http: the type,
3, as for classification category, generally do not go in the intent set it, if you write intent receiver, in manifest.xml activity Intentfilter contains Android.category.DEFAULT So that all Intent that do not set the category (Intent.addcategory (String c);) will match this category.
4, Extras (additional information), is a collection of all other additional information. You can use extras to provide extended information for your component, such as, if you want to perform the "Send e-mail" action, you can save the e-mail message's title, body, and so on in extras, to the e-mail sending component.
Intentfilter (Intent Filter)
Why introduce Intentfilter?
Answer: For an explicit intent, its recipient has been specified, so the system will automatically send this intent to the specified component. However, for implicit intent, because the component name attribute is not specified, the system does not know which component name to send it to, so the system directly sends it out, so that all components have the right to receive, which requires defining which intent a component can receive. So we introduced the Intentfilter (intent filter).
What types of data can be passed when Intent passes data?
Intent can pass a very rich range of data types, Java's basic data types and String and their array form can be passed, in addition to the implementation of the Serializable and Parcelable interface objects.
the difference between Serializable and parcelable?
1. When using memory, parcelable analogy Serializable high performance, so we recommend the use of Parcelable class.
2.Serializable generates a large number of temporary variables when serializing, causing frequent GC.
3.Parcelable cannot be used when you want to store data on disk. Although Serializable is inefficient, in this case it is
You use Serializable. Realize:
1 Serializable implementation, only need to inherit the Serializable can. This simply marks the object and the system automatically serializes it.
2 Parcelabel implementation, you need to add a static member variable CREATOR in the class, this variable needs to inherit the Parcelable.creator interface.
For ContentProvider and intent related interview questions, this chapter summarizes this first. We hope to help you.
The level is limited, if have errors and omissions, welcome to correct, criticize, if need reprint, please indicate source –http://blog.csdn.net/vfush, thank you!
Android face test summary Android Basics (ii)