Android Development Series logs-(6)

Source: Internet
Author: User

1. Download *
1. multi-thread download
Enable multiple threads, specify the same URL, and specify the same file
Different threads specify different ranges when requesting URLs, and different writes write seek () to different locations when writing the same file
Each thread is responsible for downloading part of it.
2. resumable upload
During the download process, the completed progress is saved for each part of the data downloaded.
At the beginning of the next time, read the progress of the previous completion from the file.

Ii. Handler *****
1. What is handler?
Handler can be used for communication between threads. The interface components in android can only be modified in the thread that creates the interface. If the main thread creates the interface, the new thread cannot be modified.
In some cases, we must modify the main thread interface in the new thread, and then we can use handler to communicate.
2. How to Use
Sendmessdage
In the new thread, call the sendmessage () method through the reference of handler to send a message object
The thread that creates the handler executes the handlemessage () method to obtain the message object sent by the new thread.
Post
Call the post () method through the reference of handler in the new thread to send a runnable object
The thread that creates the handler executes the run () method in runnable.

3. ANR exception
1. What is an ANR exception?
Application not Response Application Program No response. When the user does an operation but the Android system does not process it within 6 seconds, an ANR exception occurs in the program.
2. Why does ANR exception occur?
The processing of user operations in the Android system is performed in the main thread. If our program performs some time-consuming operations in the main thread, the user's operations cannot be processed in 6 seconds, an exception occurs.
3. How can this problem be solved?
Place time-consuming operations in the new thread for execution
If you need an operation interface, use handler for processing.

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.