![](/img/trans.png)
[英]How to get context of a non activity class with no Application Class in a module
[英]How to get the application context from a “non-graphic” class
我有一个处理SQLite操作的“数据库”类。 其构造函数的一部分是应用程序的上下文。 到目前为止,还不错,但是现在,我有一个“监视器”类,它扩展了需要使用该数据库类的BroadcastReceiver,并且我没有上下文来构建该实例。 因此,有两种选择:
谢谢
BroadcastReceiver
的onReceive
方法是否不将Context
作为参数?
@Override
public void onReceive(Context context, Intent intent) {
MyDataBase myDb = new MyDataBase(context);
...
}
您不能从那里得到context
吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.