Get the Application Context In Fragment In Android?

后端 未结 8 1498
無奈伤痛
無奈伤痛 2020-12-02 08:36

I have stored some data to a Global Class By using the Application Context In One Activity. Later I have to Retrieve those values in A Fragment. I have done something like t

8条回答
  •  盖世英雄少女心
    2020-12-02 09:20

    In Support Library 27.1.0 and later, Google has introduced new methods requireContext() and requireActivity() methods.

    Eg:ContextCompat.getColor(requireContext(), R.color.soft_gray)

    More info here

提交回复
热议问题