问题描述
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 (将#修改为@)