【发布时间】:2018-11-12 08:40:20
【问题描述】:
我正在使用意图调用一个服务类,该服务类扩展了其他一些类(意图除外)。
我想在调用服务类时传递 DatabaseReference。
有什么可能的方法来做到这一点?我曾想过使用 SharedPrefrences,但我也想不出一种传递上下文的方法。
也可以在新类中创建数据库引用,但我在 MainActivity 中使用身份验证,所以这样做也有点棘手。
我的服务等级:
public class NLService extends NotificationListenerService {
private DatabaseReference mDatabaseReference;
}
【问题讨论】:
-
为什么不是 DatabaseReference 实例?您从单例模式中获得 DatabaseReference 的实例。您不需要将 DatabaseReference 作为参数传递。
-
@hjchin 不知道,你能解释一下吗。谢谢!
标签: android android-intent sharedpreferences