Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Taking control overThreadingin Android                      Tobias Ekblom                                      www.appland...
Threading in Android   • To achieve responsivness   • All heavy work on background thread   • Updates of the ui on the ui-...
AsyncTask • Class for threading provided by Android • Methods   – doInBackground()   Background thread   – onPostExecute()...
.LIVE CODEAsyncTask
Referencehttp://developer.android.com/reference/android/os/AsyncTask.html                                   1.5           ...
Taking control with a queue AsyncTask 1   AsyncTask 2   AsyncTask 3                AsyncTask                              ...
Summary • Threading – a must have for a responsive   application • Android switching between serial and   parallell excecu...
Upcoming SlideShare
Loading in …5
×

Threading in Android

2,563 views

Published on

A short presentation of threading in Android, by Tobias Ekblom, developer at Appland AB. The presentation was held at the ScanDev 2012 conference in Gothenburg, Sweden.
@tobiasekblom on Twitter

Threading in Android

  1. 1. Taking control overThreadingin Android Tobias Ekblom www.appland.se
  2. 2. Threading in Android • To achieve responsivness • All heavy work on background thread • Updates of the ui on the ui-threadUi-thread Progress Progress Publish update update Background-thread Fetching data from Server Fetching ... Done.
  3. 3. AsyncTask • Class for threading provided by Android • Methods – doInBackground() Background thread – onPostExecute() or onProgressUpdate() ui-thread • .execute(params) !
  4. 4. .LIVE CODEAsyncTask
  5. 5. Referencehttp://developer.android.com/reference/android/os/AsyncTask.html 1.5 1.6 – 3.0 3.x > 3.0 3.x Do login Background thread 1 1 ? 1 Fetching user data Background thread12 2 ? 2 Fetching user data Background thread23 3 ? 3
  6. 6. Taking control with a queue AsyncTask 1 AsyncTask 2 AsyncTask 3 AsyncTask Task 1 Task 1 Task 2 Task 3 Task 2 Task 3 @Override protected Task[] doInBackground(Task... queue) { for (Task task : queue) { task.execute(); publishProgress(task); } return null; }
  7. 7. Summary • Threading – a must have for a responsive application • Android switching between serial and parallell excecution • Take control with a queue

×