Passing Activity Context to constructors to use internally - is this bad

后端 未结 3 1245
情话喂你
情话喂你 2021-02-04 01:52

Is it bad practice to pass the Context to a constructor and save it as a private variable for internal use? The other option is to pass the Context as a parameter to methods th

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 02:26

    Often, all you need is the ApplicationContext, so what you can do is pass this.getApplicationContext() instead of just this. Your app context exists for the lifetime of the app anyway, so it's not a memory leak.

提交回复
热议问题