But let’s say that you have two tasks that need to run sequentially, and both of them are implemented asynchronously.Because you are already running a background thread with , call the second task. So, potentially what you could do is queue the second task at the time that the first task finishes.
A lot of code is needed to make the query, access the database engine, receive the results, sort them, and put them in your , your UI interaction can be really be bogged down. As you do more and more work that interrupts or shares time with the UI thread, the more the application will tend to skip and lag, and animations will fail to update properly.
You might be thinking that once, you read from shared preferences on the UI thread, and nothing bad happened. The user might wonder what is wrong with the app, and the worst case happens if the user is made to wait so long that they get an error message that says, “Application not responding. ” That is the equivalent of you, the developer, suddenly walking around with a giant “Kick Me” sign taped to your back.
A fairly common example of this is trying to make a network call in your application. For a less extreme example, let’s return to the list view idea.
Let’s say that instead of populating a static list, you want to query your local database and insert the results of that query into your list.
This quote also calls attention to the fact that you are responsible for the life cycle of any alternative threads that you create.
Android has a lot of architectural options to help you with this.
With the resources that are free, the processor will try to draw the list for you.
However, some code that you add to an can run for so long that it is then not actually allowed by the platform to run on the UI thread. The platform lets you do far more than you should be doing on the UI thread.
That sounds very convenient, but the caveat to keep in mind while using this technique is that it is meant for very simple operations that will not get more complex over time.