New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix React Native Null Activity #572
Conversation
• In some cases, especially with projects using the react-native-navigation dependency, the initial Activity would be null, preventing the SDK from initializing. • Added a check that will launch a re-attempt timer if this occurs. • Updated build.gradle to use a newer version (26.0.2)
if (activity == null || oneSignalInitDone) { | ||
Log.e("onesignal", "Unable to initialize the OneSignal SDK because activity is null " + (activity == null) + " or oneSignalInitDone" + oneSignalInitDone); | ||
|
||
if (activity == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what values are on mReactApplicationContext
but can we get an Android Context
from this if getCurrentActivity()
gives us null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkasten2 getCurrentActivity()
is what is now used in RN to get the current activity. The old way of getting the activity (from the ReactApplicationContext object) is deprecated
https://github.com/facebook/react-native/releases/tag/v0.29.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe mReactApplicationContext.getApplicationContext()
should always be non-null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkasten2 mReactApplicationContext.getApplicationContext()
behaves the same way.
It seems that as of 2016, React-Native no longer guarantees this method will return a non null activity at the start of the app. So I think I'll just change it to get the activity from mReactApplicationContext
and still check for null, and if it's null, re-check in 50ms. It appears this resolves a pretty common issue in RN applications.
• Changes how the SDK gets a reference to the current activity during initialization
• Changed the SDK so that if, during initialization, the initial activity does not exist, the SDK will use the application context instead
Actually I still encounter this. Not seeing my device on the users list and when using function to get the player id it returns |
@avishayil |
• In some cases, especially with projects using the react-native-navigation dependency, the initial Activity would be null, preventing the SDK from initializing.
• Added a check that will launch a re-attempt timer if this occurs.
• Updated build.gradle to use a newer version (26.0.2)
• Fixes #516, #547