Android Key Knowledge

Source: Internet
Author: User

1. Relationship between handler and Looper and MessageQueue and message

Handler: is the thread that handles the time-consuming operation of the main thread (UI thread), through the post message to the MessageQueue queue, using handler needs to implement the Handlermessage method by updating the main thread UI

Looper: Each Looper corresponds to a MessageQueue, Looper.prepare () will initialize Looper and MessageQueue before handler,   Finally, the Looper.loop method will circulate the message to the specified handler, and the API method has a msg.target.dispatchMessage (msg); This is the call between Looper and handler.


2. Advantages and disadvantages of hander and Asynctask

Asynctask implementation of the principle and the advantages and disadvantages of application

Asynctask, a lightweight asynchronous class provided by Android, can directly inherit Asynctask, implement asynchronous operations in a class, and provide interface feedback about the current level of asynchronous execution (UI Progress updates can be implemented via interfaces). The final feedback executes the result to the UI main thread.

Advantages of Use:

Simple, fast

Process controllable    

Disadvantages of using :

It becomes complex when multiple asynchronous operations are used and UI changes are required.


Handler the principle of asynchronous implementation and its application advantages and disadvantages

When Handler is implemented asynchronously, it involves Handler, Looper, Message,thread four objects, The process of implementing asynchrony is that the main thread initiates the thread (child thread) to run and generates Message-looper to get a message and pass it to Handlerhandler to get the message in Looper, and make UI changes.

Advantages of Use:

Clear structure with clear function definition

For multiple background tasks, simple, clear

Disadvantages of using:

in a single background asynchronous processing, it appears too much code, the structure is too complex (relativity)



3, Android inside several common storage methods

A, Content provider

1) ContentProvider provides a unified interface for storing and reading data

2) using ContentProvider, applications can share data

3) Many of the data built into Android are used in the form of ContentProvider for developers to call (such as video, audio, images, contacts, etc.)

First register the provider permission in the Androidmanifest.xml, and then through Getcontentresolver () and then get the Contentresolver () object can be similar to the application of database operations and additions and deletions to change, The required parameters are the URI and the parameter values, and the query generally gets the cursors cursor to get the property value by traversing the cursor

B, sharedpreferences

in fact, Sharedpreferences is dealing with a key-value (key-value pair). Sharedpreferences is often used to store some lightweight data. by Getsharedpreferences () to get the Sharedpreferences object and then get the edit object to put the value into the object to change, Finally, Edit.commit () is required to store the object in a file, and finally, it is saved as a file under the specified path of data/data.

  C, SQLite store  

SQLite is a lightweight small database, although relatively small, but relatively perfect function, some common database basic functions also have, in the current embedded system using the database is more, because it occupies little system resources

You need to inherit Sqliteopenhelper and then Helper.getwritabledatabase () to get the Sqlitedatabase object, which can be used to increase the deletion of data, providing the Curd method in the form of key value

D, IO stream storage

E, WebView networked storage



Android Key Knowledge

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.