안드로이드 개발자 모임 게시판
(글 수 7,997)
안녕하세요 아즈라엘 입니다.
Thread 에서 데이터를 주고 받기 위해서 Message 를 Queue에 넣고
Looper가 루핑을 통해 확인을 하고 이것들을 핸들러가 건네주는데요..
메인스레드외에 서브스레드에서 Looper 를 등록하고 돌리기 시작하면
성능을 좀먹는 이유중 하나가 될 수 있을까요?
지금 메인 스레드 외에 항상 2개~3개가 돌고 있고 화면마다 처음엔 4~5개까지
늘어나고 있으며 스레드에는 루퍼가 각각 존재하고 있습니다.
아무래도 화면 그리는 시점이나 그밖의 다른 성능들이 폰의 원래 성능보다
떨어지는듯 하여 여러분의 의견은 어떠하신지 물어보고 싶네요 ~!!ㅎ
2012.06.29 15:37:34
근데 멀티 쓰레드에서 UI 쓰레드에 접근하는 방식들이 여러가지가 있는데
Handler.sendMessage
Handler.post
runOnUiThread
AsyncTask
Thread 에서 임의로 Looper 에 접근하는 방식
들이 있는데
솔직히 가독성이나 유지보수성이 그나마 나은건 Handler.sendMessage 이고
어차피 저것들 모두 내부적으로는 Ui Thread 로 Looper 가 땡겨서 접근하는 방식이기 때문에 어쩔 수 없습니다.
2012.06.29 16:28:01
/**
* Sends a Message containing only the what value.
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessage(int what)
{
return sendEmptyMessageDelayed(what, 0);
}
/**
* Sends a Message containing only the what value, to be delivered
* after the specified amount of time elapses.
* @see #sendMessageDelayed(android.os.Message, long)
*
* @return Returns true if the message was successfully placed in to the
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
public final boolean sendEmptyMessageDelayed(int what, long delayMillis) {
Message msg = Message.obtain();
msg.what = what;
return sendMessageDelayed(msg, delayMillis);
}
원본 소스입니다 :)
좀 깨지긴 하지만 여튼 위와 같이 처리되네요




저는 Handler 를 사용하지않고 Activity.runOnUiThread 를사용합니다.. 이렇게사용하면 성능이줄지는 않지 않을까요?