Android

asynctask get method

aucd29 2015. 8. 7. 16:54
http://developer.android.com/reference/android/os/AsyncTask.html

asynctask 내에 get 을 이용하여 sync 하도록 doBackground 에 result 를 얻을 수 있다.

class TestAsyncTask extends AsyncTask<Void, Void, Long> {
     protected Long doInBackground(Void... data) {
         Long value = 10;
         return value;
     }

     protected void onPostExecute(Long result) {
         Log.d(TAG, "res : " + result);
     }
}

일 경우 다음과 같이 사용한다.

Long result = new TestAsyncTask().execute().get();