Android Anomaly and performance optimization related interview questions-anr abnormal interview questions

Source: Internet
Author: User

What is ANR?

Application Not Responding

The main cause of ANR:

The responsiveness of the application is monitored by the activitymanager and WindowManager system services, which can cause the ANR to be monitored when the main thread in the activity clicks more than 5 seconds to respond or if the wood responds in the broadcast UI thread for more than 10 seconds. Here's a list of the details:

    • The main thread is blocked by I/O operations (the network IO is not allowed in the main thread after 4.0).
    • There is a time-consuming calculation in the main thread.

The main reason for the ANR: What operations are on the main thread in Android?

    • All life cycle callbacks for an activity are performed on the main thread.
    • Service defaults are performed on the main thread.
    • The Broadcastreceiver OnReceive callback is performed on the main thread.
    • The Handlemessage,post (Runnable) of a looper that is not using a child thread is performed on the main thread of the handler.
    • In addition to Doinbackground, the Asynctask callback is performed on the main thread.

How to resolve ANR:

    • Use Asynctask to process time-consuming IO operations.
    • Use thread or handlerthread to increase priority.
    • Use handler to handle time-consuming tasks for worker threads.
    • The activity's OnCreate () and Onresume () callbacks try to avoid time-consuming code.

Android Anomaly and performance optimization related interview questions-anr abnormal interview questions

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.