4. Application 구현 및 용도
Base class for those who need to maintain global application state.
You can provide your own implementation by specifying its name in your
AndroidManifest.xml's <application> tag, which will cause that class to be
instantiated for you when the process for your application/package is created.
Application은 Application이 초기화되는 최초에 한 번 호출이 되며 1개의
Instance가 생성되어 유지되는 클래스 입니다. 우리는 이를 활용해서, Application
범위에서 관리가 필요한 항목을 초기화 및 관리가 가능합니다.
초기화는 Application.onCreate에서 진행이 될 수 있습니다.
그렇지만, onTerminate는 에뮬레이터 환경에서만 발생되며, 실 장비에서는
발생이 되지 않습니다. 이 점에 대해서 주의를 해서 자원 관리를 해야 합니다.
5. Application & Singleton
가만히 보면, Singleton들을 대해서 Application에 등록해서 관리를 하면
편하게 할 수 있을 것 같다. 그렇지만, 이에 대해서 android는 reference에서
다음과 같이 이야기 하며, Application을 Singleton 구성에 사용은
하지 않는 것을 권장하고 있다.
There is normally no need to subclass Application.
In most situation, static singletons can provide the same functionality
in a more modular way. If your singleton needs a global context
(for example to register broadcast receivers), the function to retrieve it can
be given a Context which internally uses Context.getApplicationContext()
when first constructing the singleton.
6. 그래도 Application을 써보자.
지금부터 보는 코드 구조는 권장되지 않습니다. 본 코드 구조는 Application을
활용하는 예제를 보는 차원에서 작성이 된 점을 유념 바랍니다.
네트워크 모니터링용
유틸성 클래스를 global하게
한 개를 사용하기 위해,
Application에 등록합니다.
9. 네트워크 연결 상태에 대해서~
1. 상세 정보: NetworkInfo.getDetailedState()
2. 조금은 단순화된 상태: NetworkInfo.getState()
대부분 경우에 본 함수를 통해서 우리는 원하는 상태를 얻을 수 있습니다.
3. 우린 이걸 더 단순화해서
연결 상태를 안정/불안정/끊김
으로 정의를 하고자 합니다.