안드로이드에서 getContext(), getApplicationContext(), getBaseContext(), this의 차이가 뭔가요?

조회수 18745회

안드로이드에서 getContext(), getApplicationContext(), getBaseContext(), this의 차이가 뭔가요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    View.getContext()

    현재 실행되고 있는 View의 context를 return 하는데 보통은 현재 활성화된 activity의 context가 된다.

    Activity.getApplicationContext()

    어플리케이션의 Context가 return된다. 현재 activiy의 context 뿐만 아니라 application의 lifeCycle에 해당하는 Context가 사용된다.

    ContextWrapper.getBaseContext()

    자신의 Context가 아닌 다른 Context를 access하려 할 때 사용한다. ContextWrapper는 getBaseContext()를 경유해서 Context를 참조할 수 있다.

    this

    View.getContext()와 같다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)