We have seen different techniques to create our multithreaded application and when to use them. The right structure to use depends on a lot of various factors; it's up to the developer to treasure what we said and apply the appropriate framework in each case. However, our primary goal is to provide a fluid UI to the user, avoiding the Application Not Responding dialog, lags, and any obstacle to the correct execution of the UI thread. For this, Android provides some tools that we are about to see in the following pages.
We already dealt with this tool in Chapter 4, Memory, while talking about memory leaks. However, this tool can also help us find and notify threading problems.
To use it we need to know what we are searching for and how to be informed that a threading problem is occurring. For this, we need to set ThreadPolicy
to the StrictMode
class, using a ThreadPolicy.Builder
class. This way we can be notified of the following occurring problems:
detectCustomSlowCalls...