이번 포스팅은 Android Build 오류에 대하여 알아보도록 하겠습니다.
< Error>
This Handler class should be static or leaks may occur (anonymous android.os.Handler)
< Solution >
1. Handler class는 object가 아니라 static class로 선언이 되어야 하는데 그러지 않아서 오류가 발생하는 것입니다.
2. 여기서 한 가지....
나는 Handler를 아래와 같이 static 으로 선언하였는데 왜 이런 오류가 계속 뜨는 거지?
public static final Handler myHandler = new Handler() {
public void handleMessage(Message msg) {
.........
}
}
3. 원인 : Handler 객체는 변수로써 static으로 선언하였지만 내부에 있는 익명의 클래스는 static이 아니기 때문에 계속 오류가 발생하는 것입니다.
4. 해결: Handler 객체를 상속받은 새 static 클래스를 만든 후 Logic을 여기서 구현하시면 됩니다.
// 변수로 Handler 선언
private Handler mHandler = new EunHandler();
private static class EunHandler extends Handler {
public void handleMessage(Message msg) {// ..................
// Logic 구현// ..................
}
};
'Development > Error' 카테고리의 다른 글
| [Error] Android Intent URI 오류 해결 방법 (0) | 2019.09.06 |
|---|---|
| [Error] Can only replace keys with same alias (0) | 2019.09.01 |
| [Error] API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()' (0) | 2019.08.29 |
| [Error] Unsupported key algorithm: RSA. OnlyEC supported (0) | 2019.08.28 |
| [Error] exposed beyond app through ClipData.Item.getUri() (0) | 2019.08.27 |