In this article, I would like to share about of my experience with the AsyncTask on Android. Some time ago, when I was not of apprentice in Pernix. I tried so hard to create an app for Android. The app was a game similar to Mario and Bomberman. As already you know, to create a game is necessary to have a layout that continuously updates and by down the logic keep working. To do that is necessary use executions threads, a thread to run the interface and another that can keep the logic. When I designed my game, I knew about of this issue and I created a thread to prevent it. But the app always crashed when used the thread. I tried to solve this problem by a week, but I never could do it... Until the last week
Last week I was working on a query to Quickblox, that was about the dialogs user. To keep the interface working and make the query is necessary a thread. I was investigating about that and I found that exist 2 ways to fix the issue of the threads. The first solution is similar to what I did to my game, but with the difference that the thread must be executed in the context of the layout. The second answer is to implement a library called AsyncTask that helps me to control the events. To used is necessary implement create a class that extends and override the method of the library. In the next image explains the structure of the class more clearly.
By lucky, I asked Macho about that problem and he explained to me that the asynchronous task as already implements with the Quickblox library, then I didn't need to be careful with this problem.
