Android Face questions and Answers (iii)

Source: Internet
Author: User
Tags sqlite database

1, list map set three interfaces, access to elements, what are the characteristics of each?
Both list and set are collections of single-column elements that have a common parent interface, collection.
Duplicate elements are not allowed in set.
Save element: The Add method has a Boolean return value that returns True when there is no element in the collection, when the Add method can successfully join the element, and when the collection contains an element equal to the equals of an element, the Add method cannot join the element and return the result to false.
Take the element: can not say that the first few, only the iterator interface to get all the elements, and then iterate through each element.
The list represents a set of sequential orders.
Save elements: When you call the Add (object) method multiple times, each time you join an object that is sorted sequentially, or you can jump in the queue, that is, by calling the Add (int index,object) method, you can specify where the current object will be stored in the collection.
Take element: Method 1:iterator interface Get all, traverse each element individually
Method 2: Call Get (Index i) to specify how to take the first few.
Map is a two-column collection, each time you store, to store a pair of key/value, cannot store duplicate key, this repeating rule is equal to equals.
Stored elements: Put method: Puts (obj key,obj value).
Fetch element: Use the Get (Object key) method to obtain the corresponding value according to key;
You can also get a collection of all the keys, and you can also get a collection of all the value;
You can also get a collection of Map.entry objects that combine key and value.
Lists hold elements in a particular order, and can have repeating elements. Set cannot have duplicate elements, internal ordering. Map save Key-value value, key cannot be duplicated.
2. What is collection?
Collection is the ancestor interface of the collection class, and the main interface for inheriting it is set and List. Collections is a helper class for a collection class that provides a series of static methods for searching, sorting, threading, and so on for various collections.
3. ArrayList vs Vector
Both ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly, and the Vector Due to the use of the Synchronized method (thread-safe), usually the performance of the ArrayList poor, and LinkedList using a doubly linked list for storage, index data by ordinal need to forward or backward traversal, but when inserting data only need to record the item before and after items, So the insertion speed is faster.
4, HashMap vs Hashtable
HASHMAP is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the Map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), because the non-thread security efficiency may be higher than Hashtable. HASHMAP allows NULL to be used as a entry key or value, and Hashtable is not allowed.
HashMap Hashtable contains method removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding. Hashtable inherits from the Dictionary class, and HashMap is an implementation of the Map interface introduced by Java1.2. The biggest difference is that the Hashtable method is Synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HASHMAP must provide external synchronization.
The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there is no big difference in performance.
5. Sleep vs Wait
Sleep is a threading class (thread) method that causes this thread to pause execution for a specified time, giving the execution opportunity to other threads, but the monitoring state remains and is automatically restored after the time. Calling sleep does not release the object lock.
Wait is a method of the object class that calls the wait method on this object to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only after the Notify (or Notifyall) method is issued for this object does the thread enter the object lock pool ready to get the object lock into the running state.
6. Android Touch Event distribution mechanism
View key functions: Dispatchtouchevent,ontouch,ontouchevent,onclieck.
ViewGroup key function: Dispatchtouchevent,onintercepttouchevent,ontouchevent.
Onintercepttouchevent returns true to represent the touch event of the Intercept sub-view, which is then handled by the dispatchtouchevent of the parent view.
For detailed procedures, please visit another blog post: http://blog.csdn.net/wdong_love_cl/article/details/51477607
7, the Android breakpoint continued to download the implementation of the general idea
Take the download as an example:
Use HttpURLConnection to download and write files using Randomaccessfile.
1, need to get the file size to download and set to local file, using:
int filesize = 0;
FileSize = Httpurlconnection.getcontentlength ();
Randomaccessfile file;
File.setlength (filesize);
2, according to the size of the file and the number of threads to determine the size of each thread needs to download, such as: File size is 8M, there are 4 threads, then each thread will need to download 2M.
3. Determine the start and end location of each thread download Httpurlconnection.setrequestproperty ("Range", "bytes=" + startposition + "-" + endposition);
4, can use File.seek (position) to specify from where to start writing;
8, handler.sendmessage the approximate steps
Message is stored in Message Queuing:
Handler.sendmessage ()-->handler.sendmessagedelayed ()-->handler.sendmessageattime ()-->msg.target = this[ is Handler];queue.enqueuemessage () ==> adds msg to the message queue
Remove and process from Message Queuing:
Looper.loop () [dead loop, constantly fetching messages from message Queue]--> msg.target.dispatchMessage (msg)--->handler.handlemessage ()
For detailed procedures, please visit another blog post: http://blog.csdn.net/wdong_love_cl/article/details/43572773
9, Android ScrollView nested viewpager sliding conflict
Two workarounds:
1, rewrite the Onintercepttouchevent method of the ScrollView class, if it is found to be horizontal sliding, then return False in the method, so do not intercept Viewpager, The Ontouchevent method of Viewpager will be executed;
2, rewrite the Ontouchevent method in Viewpager, if Motionevent.action_down or motionevent.action_move horizontal sliding set getparent (). Requestdisallowintercepttouchevent (True) if the vertical slide is set to false.
10, the use of Android fregment
For details see: http://blog.csdn.net/wdong_love_cl/article/details/51569440
11, String str1= "abc" and string Str1=new string ("abc"); What is the difference between the two?
The former compiles "abc" into a string constant pool in the stack, and uses STR1 to refer to the reference to the string constant, which, when running, creates a string object "ABC" in the heap area and uses str1 to point to the object for reference. So the reference to the two str1 refers to a different memory address, and the logic outputs the same content.
12, the official Android recommended application development using MVC mode, what is MVC?
MVC is an acronym for Model,view,controller, and MVC consists of three parts:
Model object: Is the main part of the application, and all business logic should be written on that layer.
View object: Is the part of the application that is responsible for generating the user interface. It is also the only layer that the user can see in the entire MVC architecture, receiving input from the user and displaying processing results.
Controller (Control) object: is based on the user's input, control the user interface data display and update Model object state part, the controller more important a navigation function, in response to the user to start the relevant events, to model processing.
Android encourages weak coupling and component reuse, and MVC in Android is embodied in the following:
1) View layer: The general use of XML file interface description, the use of the time can be very convenient to introduce, of course, how you learn more about Android, you can think of Android can also use javascript+ HTML and so on as the view layer, of course, there is a need for the communication between Java and JavaScript, fortunately, Android provides a very convenient communication between them implementation.
2) control layer (Controller): The task of Android control layer usually falls on the shoulders of many acitvity, this phrase also implies do not write code in acitivity, to through activity delivery model business Logic layer processing, Another reason for this is that the response time of Acitivity in Android is 5s, and if time-consuming operations are put here, the program is easily recycled.
3) Model: the operation of the database, the operation of the network, etc. should be processed in the model, of course, business calculations and other operations must be placed in the layer.
13, how to publish the SQLite database (dictionary.db file) with the apk file?
You can copy the Dictionary.db file to the Res/raw directory in your project. All files in the Res/raw directory are not compressed, so that the files in that directory can be extracted directly.
14. How do I open a database file in the Res/raw directory?
You cannot open a database file in the Res/raw directory directly in Android, but you need to copy the file to a directory on your phone's memory or SD card The first time the program starts, and then open the database file. The basic method of replication is to use the Getresources (). Openrawresource method to obtain the InputStream object of a resource in the Res raw directory, and then write the data in the InputStream object to the corresponding file in the other directory. In Android, you can use the Sqlitedatabase.openorcreatedatabase () method to open a SQLite database file in any directory.



Android Face questions and Answers (iii)

Related Article

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.