hander와 thread 없이 비동기 동작을 위한

private void firstAction(){
(new AsyncTask <MainActivity, Void, MainActivity>(){
@Override
protected MainActivity doInBackground(MainActivity... params) {
return params[0];
}

@Override
protected void onPostExecute(MainActivity result) {
//super.onPostExecute(result);
result.firstLoad();
}

}).execute(this);
}

MainActivity 속의 onCreate 안에서
firstAction();
라고 호출하면 따로 쓰레드를 만들어서
MainActivity.firstLoad()
를 호출하도록 만든 메소드.
(firstLoad 메소드는 JSON통신, UI기본 설정 하는 등의 동작을 함)

# 왜?
Skipped 64 frames!  The application may be doing too much work on its main thread.
같은 메세지가 나오면서 json 읽어오는 동작이 안되기에
따로 쓰레드를 만들어 동작하도록 함.
#주의 
doInBackground 
안에서 UI를 제어하면 안됨. 에러남
onPostExecute 안에서 해야함
상세한건 한번 해보고 에러 검색해보자!
(핸들러의 UI제어 가능 어쩌고 저쩌고 문제)
댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
제목 작성자 날짜
공대여자
공대여자
mins01
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자