http://goo.gl/70pR
Painless Threading
고통 없는 쓰레드
AsyncTask를 사용하거나 사용하지 않더라도, 항상 기억하라 두가지 법칙 싱글 쓰레드 모델에서
You can specify the type, using generics, of the parameters, the progress values and the final value of the task
The method doInBackground() executes automatically on a worker thread
onPreExecute(), onPostExecute() and onProgressUpdate() are all invoked on the UI thread
The value returned by doInBackground() is sent to onPostExecute()
You can call publishProgress() at anytime in doInBackground() to execute onProgressUpdate() on the UI thread
You can cancel the task at any time, from any thread
클래스화
생성,행
Painless Threading
고통 없는 쓰레드
AsyncTask를 사용하거나 사용하지 않더라도, 항상 기억하라 두가지 법칙 싱글 쓰레드 모델에서
Regardless of whether or not you use AsyncTask, always remember these two rules about the single thread model:
- Do not block the UI thread, and
UI 쓰레드를 묶어 두지 말라
- Make sure that you access the Android UI toolkit only on the UI thread.
오직 UI 쓰레드 위에서만 안드로이드 UI 툴킷을 접근한다는 것을 명심하라
AsyncTask
just makes it easier to do both of these things.
AsyncTask는 단지 이런 것의 모두를 쉽게 만들어 준다.
source code of Shelves (ShelvesActivity.java and AddBookActivity.java)
Photostream (LoginActivity.java, PhotostreamActivity.java and ViewPhotoActivity.java)
We highly recommend reading the source code of Shelves to see
how to persist tasks across configuration changes and
how to cancel them properly when the activity is destroyed.
어떻게 액티비티가 파괴될때 그것들을 적절하게 취소하는가
클래스화
private class DownloadFilesTask extends AsyncTask{ protected Long doInBackground(URL... urls) { int count = urls.length; long totalSize = 0; for (int i = 0; i < count; i++) { totalSize += Downloader.downloadFile(urls[i]); publishProgress((int) ((i / (float) count) * 100)); } return totalSize; } protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]); } protected void onPostExecute(Long result) { showDialog("Downloaded " + result + " bytes"); } }
생성,행
new DownloadFilesTask().execute(url1, url2, url3);
'0.일반개발' 카테고리의 다른 글
단축키 (0) | 2010.10.07 |
---|---|
자동완성 기능 - 이클립스 eclipse - Java-Editor-Content Assist (0) | 2010.10.07 |
안드로이드 user permission 전부 전체 리스트 (0) | 2010.10.05 |
Eclipse 사용법들 (0) | 2010.10.05 |
갤럭시 에스 Galaxy S 도대체 왜 ? (2) | 2010.10.04 |