Needing Context in non-Activity classes

前端 未结 7 1729
轻奢々
轻奢々 2020-12-14 06:10

I have some classes within my application that need to call Android functions that require the Context as a parameter. I don\'t have it as the class is not a subclass of the

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 06:46

    Pass it at class instantiation and keep it.

    One typical example is when you create a db helper. See this link

提交回复
热议问题