• Skip to main content
  • Skip to footer

B4X

Develop Android, iOS and IoT applications

  • Home
  • Products
    • B4A (Android)
    • B4i (iOS)
    • B4J (Desktop)
    • B4R (Arduino)
  • Showcase
  • Store
  • Learn
    • General
    • Guides
    • Video Tutorials
    • Glossary
  • Teach
  • Blog
  • Community
A B C D F G H J M N Q S T U X

All

ANR

ANR – Application Not Responding, is a system dialog that appears in Android apps when the app becomes unresponsive.
Applications are expected to be responsive. A responsive application is an application that responds quickly to user interactions.
Messages about user interactions, for example when the user touches the screen, are sent to an internal message queue. Whenever the main thread is free it checks the message queue for new messages and processes them. The result might be a button click event, an update to an ongoing animation and so on.
As long as the main thread is busy running other code, it will not process the message queue.
If a user interacts with the device and the message is not processed for about 5 seconds then an ANR dialog will be displayed, asking the user whether they want to continue waiting or to close the app:

Code for above example:

Sub Activity_Create(FirstTime As Boolean)
	Do While True
		If False Then Return
	Loop
End Sub

In order to keep the app responsive we need to avoid making too much work on the main thread.
In B4X almost all of our code is run on the main thread, however slow tasks such as network communication are always done on background threads. This is also true for the async database operations ([B4X] SQL with Wait For) and many other cases where the library or framework takes care of executing the task in the background and raising an event on the main thread when done. Overall, it is quite rare to see an ANR dialog with B4X (in release mode).

Related topic: NetworkOnMainThreadException

Written by Erel Uziel

Footer

Top

  • Home
  • Products
    • B4A (Android)
    • B4i (iOS)
    • B4J (Desktop)
    • B4R (Arduino)
  • Showcase
  • Store
  • Learn
    • General
    • Guides
    • Video Tutorials
    • Glossary
  • Teach
  • Blog
  • Community

About us

Follow us:

Latest Versions

B4A v10.5 (changelog)
B4i v6.80 (changelog)
B4J v8.80 (changelog)
B4R v3.50 (changelog)

Contact Us

support@basic4ppc.com

Privacy Policy

Privacy Policy

Copyright © 2021 · Anywhere Software. Android is a trademark of Google Inc. iOS is a registered trademark of Apple. Arduino is a trademark of Arduino. Java is a trademark of Oracle.