如何解决如何在Android的FirebaseMessaging Service上添加React Application上下文?
public class MessagingService extends FirebaseMessagingService {
...
FBMessagingHelper notificationHelper = new FBMessagingHelper(this.getApplicationContext())
...
}
如何将React Application Context传递给FBMessagingHelper
我尝试了下面的代码,该代码仅在应用程序处于前台或后台时才有效。当收到应用通知时(当应用未运行时),它会崩溃。我该如何进入FBMessagingHelper
类,或者在应用程序不活跃时如何处理?
FBMessagingHelper notificationHelper = new FBMessagingHelper((ReactApplicationContext) ((MainApplication)getApplication()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext());
应用未运行时,抛出此错误:
java.lang.NullPointerException: Attempt to invoke virtual method `void.com.facebook.react.bridge.ReactApplicationContext.addActivityEventListener(com.faceebook.react.bridge.ActivityEventListener)` on a null object
FBMessagingHelper类:
public class FBMessagingHelper extends ReactContextBaseJavaModule implements LifecycleEventListener,ActivityEventListener {
private ReactApplicationContext mContext;
public FBMessagingHelper(ReactApplicationContext context) {
super(context);
this.mContext = context;
getReactApplicationContext.addActivityEventListener(this);
getReactApplicationContext.addLifecycleEventListener(this);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。