안드로이드 개발 질문/답변
(글 수 45,052)
Dialogbox 를 띄울 때 getApplicationContext()를 사용시 에러가 떨어지고..
Class명.this 또는 this를 쓰게 되면 정상적으로 돌아갑니다.
AlertDialog.Builder alert = new AlertDialog.Builder(MultiOptionDialog.this); ==> 에러
AlertDialog.Builder alert = new AlertDialog.Builder(this); ==> 정상적임.
똑같이 Context를 쓰는거러 구문오류에서는 걸리진 않는데요...
또 한가지로,
Adapter을 선언 시에는 getApplicationContext()가 정상적으로 인식이 되네요.
ArrayAdapter<String> arrAdapter =
new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_multiple_choice, arrFileList);
제가 영어 실력이 딸려서 Google API에 있는 getApplicationContext 원문을 읽어 보았지만... 이해가 가지 않아 이렇게 질문드립니다.
( 원분 일부 :
Return the context of the single, global Application object of the current process.
This generally should only be used if you need a Context whose lifecycle is
separate from the current context, that is tied to the lifetime of the process
rather than the current component.
)
분명 받는 AlertDialog.Builde 클래스 생성시 필요한 인자값은는 Context 이며
getApplicationContext 경우도 현재 프로세스의 오브젝트를 반환한다고 하는데요..
왜 에러가 떨어지는지.. 이해가 안갑니다.
에러 로그
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
머리를 굴리고 검색질을 해도 찾기가 너무 힘들어서 그렇습니다.
설명이 귀찮으시면.. 한글로 된 사이트 링크라도 부탁드립니다. 엉엉..