Closed xxsnakerxx closed 8 years ago
My usage example
analytics.js
import Analytics from 'react-native-firebase-analytics';
import { ENVIRONMENT, ENVIRONMENTS } from '../config';
// collect analytics only in production
if (ENVIRONMENT !== ENVIRONMENTS.PRODUCTION) {
Analytics.setEnabled(false);
Analytics.logEvent = (...args) => console.log('Analytics.logEvent', ...args);
Analytics.setUserId = (...args) => console.log('Analytics.setUserId', ...args);
Analytics.setUserProperty = (...args) => console.log('Analytics.setUserProperty', ...args);
}
export default Analytics;
In this case android app crashing on line Analytics.setEnabled(false);
This PR fixed this.
i'm trying to understand the difference between getCurrentActivity()
and getReactApplicationContext()
. I'm using getCurrentActivity().getIntent()
in another library but seems getReactApplicationContext() doesn't have it.
As I understand Activity
is an android view! FirebaseAnalytics.getInstance
want to receive Context! But Activity just casting to AppContext...
https://developer.android.com/reference/android/content/Context.html https://developer.android.com/reference/android/app/Activity.html
looks like getReactApplicationContext() is the correct way to go in this case. thanks
Replaced
getCurrentActivity()
withgetReactApplicationContext()
for all methods in android module, because you can call analytics methods before the app will be initialized (getCurrentActivity returns null in this case and the app crashing)