Static way to get 'Context' in Android?

前端 未结 19 2730
猫巷女王i
猫巷女王i 2020-11-21 06:36

Is there a way to get the current Context instance inside a static method?

I\'m looking for that way because I hate saving the \'Context\' instance eac

19条回答
  •  一向
    一向 (楼主)
    2020-11-21 07:13

    It depends on what you are using the context for. I can think of at least one disadvantage to that method:

    If you are trying to create an AlertDialog with AlertDialog.Builder, the Application context won't work. I believe you need the context for the current Activity...

提交回复
热议问题