Posts

Showing posts with the label Broadcast Receiver

AntiPattern: freezing a UI with Broadcast Receiver

Image
The worst thing that can happen to your app's responsiveness is an "Application Not Responding" (ANR) dialog. In android guidelines we can read: In any situation in which your app performs a potentially lengthy operation, you should not perform the work on the UI thread , but instead create a worker thread and do most of the work there. This keeps the UI thread (which drives the user interface event loop) running and prevents the system from concluding that your code has frozen. It's very important to understand what is Main Thread . When an Android app is launched, the system creates a thread for the application which is known as the main thread. If you run up any project under the debugger in Eclipse you will see the main thread. If your app ties up the UI thread for more than 5 seconds or a BroadcastReceiver does not complete within 10 seconds, Android will throw up the Application Not Responding (ANR) dialog which gives the user the opportunity t...