Background processing
Now that we have addressed how to request permission, we will slightly shift our focus on how to perform background operations. All network communications have to be done in the background. If we do it on the UI thread or main thread, we will block the UI layer and, most probably, throw an Application Not Responding (ANR) dialog. For more information, refer tohttp://developer.android.com/training/articles/perf-anr.html.
Anyway, any application targeted after Honeycomb will throw an exception NetworkOnMainThreadException
if it detects any networking operations on the main thread. For more information, refer to http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html.
We have several tools to address these points, but Android provides us with many useful mechanisms already.
Java threads
We can always use Java threads to do background work. It is good practice to use an Android provided mechanism, as using, or abusing, Java threads might lead to...