AsyncTask all i get is a blank/black texture screen

No, this is a common misconception with threads (not just in Android, but in Java and programming in general). A task takes as long as it takes, using Threads doesn't make it faster unless the task can be broken down into smaller pieces and done in parallel without interfering with each other - but that is actually not very common, and almost never the case with disk read/writes, network connections, or heavy CPU use. In fact over-using threads can actually make a task run slower: every thread competes for CPU time and it actually takes time to switch contexts from one thread to the next. So if you have too many thread context switches you could be spending a measurable amount of time moving between the threads instead of doing work.

What threads do is make tasks more responsive and makes unrelated tasks occur at the same time: you can do the disk writing in one thread and the network communication in another thread. This would mean the network comms don't have to wait for the disk writes to complete or vice-versa. The network communications take the same amount of time before or after threads, but maybe there is less wasted time where a message is waiting to be consumed but the app is busy writing to a disk.

So when you push a long-running task out of the UI thread and into a background thread you aren't making that task happen any quicker. What you are doing is allowing the User Interface thread to move on, allowing the user to interact with the application, and allowing other updates to the UI to occur while that process happens. It makes the application more responsive, which makes things appear faster to the user. Not doing so could 'hang' the UI while the process runs, and the user would think that the app is frozen or crashed.

 

 

Back  [1] [2] [3] 

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright