Fragment에서 context를 사용할 때 종종 아래와 같은 exception을 조우할 떄가 있다.
java.lang.IllegalStateException: Fragment not attached to a context.
이는 Fragment가 Activity에 Attach되지 않았을 때 context를 호출하면 발생한다.

위 코드를 살펴보면
getContext는 Nullalble
requireContext는 NonNull
그래서 getContext를 사용했다면 attach 되지 않아도
Nullable이기 때문에 null이 반환되지만
requireContext는 NonNull이기때문에
현재 context가 null이면 IllegalException을 throw한다.
Fragment의 LifeCycle을 살펴보면 onAttach가 있다.

Fragment에서 제공하는 getContext는 null을 반환할 때도 있기 때문에
안전하게 context를 사용하려면 onAttach에서 인자로 넘어오는
context를 사용하는 것이 좋다.