How to obtain application context from broadcast receiver?

前端 未结 2 1005
广开言路
广开言路 2021-01-11 10:46

I have an extension of the Application class that I need to obtain reference in a BroadcastReceiver I have created. The context passed into the \"onReceive\" is a restricted

2条回答
  •  终归单人心
    2021-01-11 11:37

    Call getApplicationContext() on the Context supplied to you in onReceive(), just as you would call getApplicationContext() on an Activity.

    I have an extension of the Application that allows me to non-statically obtain reference to several objects I need.

    While syntactically Application is not static, it has the same impact, particularly with respect to memory leaks.

提交回复
热议问题