AsyncTask 사용 관련

2015. 8. 16. 23:01 IT/Android

1. execute 할때 error

Cannot execute task: the task has already been executed (a task can be executed only once)

라는 에러 생길 경우 한번 실행된것은 다시 execute 될 수 없기 때문에

task를 execute 할때마다 매번 new instance 한 후 execute한다.

 

2. return값 사용할 경우

1) public class MyAsyncTask extends AsyncTask<String, Void, Boolean> 처럼 마지막 파라미터에 return type 설정 후 doInBackground() 안에서 return 값 설정

2) execute.get() 해서 가져옴(대신 해당 thread에서 결과값 받아 온 후 main thread 실행 됨)

 

3. execute 시 파라미터 전달 하는 방법

예)

1) doInBackground(String... params){

String param1 = params[0];

String param2 = params[1];

 

2) 호출할 때는 execute("1", "2");

Recent Posts

Recent Comments

Recent Trackbacks

Copyright © 집착남의 이야기 All Rights Reserved | JB All In One Version 0.1 Designed by CMSFactory.NET