Getting the Application Context

后端 未结 6 1209
梦如初夏
梦如初夏 2020-12-02 23:16

This might be a simple question but I just wanted to make sure I am right.

In my android application I have a constructor that uses:

activity.getApp         


        
6条回答
  •  猫巷女王i
    2020-12-02 23:48

    There is only one application context, so you should get the same one. You can have just one constructor that takes a Context, you don't really need two. Or if you wanted to make sure that you are getting the application context, and not, say, an activity one, you can have your constructor take Application as a parameter which is a Context.

提交回复
热议问题