-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Activity to onActivityResult listener interface
Summary: The Android lifecycle is weird: turns out `onActivityResult` is called before `onResume`. This means `getCurrentActivity()` could return the wrong instance, or `null` if the activity was destroyed. To give developers access to the Activity receiving the result (which is also about to become the current activity), pass it as an argumento the listener. Fixes github issue #8694. Reviewed By: donyu Differential Revision: D3704141 fbshipit-source-id: e7e00ccc28114f97415e5beab8c9b10cb1e530be
- Loading branch information
Showing
6 changed files
with
22 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fbd2e13
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.
@foghina is this not a breaking change? How can I make my module support
0.33
while also being backwards compatible?fbd2e13
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.
@marcshilling There are 2 methods, one with the old signature marked as deprecated. So you should be able to use the old signature until its removed
fbd2e13
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.
It is a breaking change if you were using
ActivityEventListener
directly, instead ofBaseActivityEventListener
. Sorry, but there was no other way. Consider using the base class in the future to avoid compilation errors as we might change the interface in the future.fbd2e13
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 am getting crash on invoking JS callback from onActivityResult after upgrading to 0.33.0 .
Stack Trace:
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.<****>, PID: 13496
AndroidRuntime: java.lang.AbstractMethodError: abstract method "void com.facebook.react.bridge.ActivityEventListener.onActivityResult(android.app.Activity, int, int, android.content.Intent)"
AndroidRuntime: at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:210)
AndroidRuntime: at com.facebook.react.XReactInstanceManagerImpl.onActivityResult(XReactInstanceManagerImpl.java:612)
AndroidRuntime: at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:134)
fbd2e13
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.
@satya164 @foghina but even using
BaseActivityEventListener
, when running on < RN 0.33, the code won't compile because the newonActivityResult
method signature does not exist. Am I missing something?EDIT: Ah, I guess I can just not mark the new signature as
@Override
and it works on both 33 and below. Sweet!fbd2e13
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.
@marcshilling Would you have to remove the
@Override
on the old signature as well then? If not then it will probably throw a compiler exception at 33 and above?fbd2e13
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.
@cbrevik not required (because the old signature is still defined as deprecated), but I went ahead and did it to prevent issues after it eventually goes away. Tested on both 33 and 32 and it works great.
fbd2e13
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.
You shouldn't have to remove any
@Override
. You should be able to compile against the newest RN but run on older RN. This is how Android works as well: you always compile against the newest SDK but put runtime checks in to ensure compatibility with older versions. In this case that would be implementing the old callback to simply call the new one.fbd2e13
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 wouldn't worry about it though, I'd just make it work with the latest RN only and if people aren't willing to upgrade they can use the older version of your library as well.
fbd2e13
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.
@subratpanda1 I catch the same problem as you. how did you solve.
fbd2e13
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.
Could not solve. I reverted back to 0.32.0.
fbd2e13
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.
Just updated to
0.33.0
. Getting the following,The code in
MainActivity.java
is the following,fbd2e13
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.
@foghina Any idea what's happening here?
fbd2e13
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'm guessing lots of people would have been using
ActivityEventListener
because even the 0.34 docs describe it as the way to add native modules. There is no mention of theBaseActivityEventListener
class anywhere in the docs.fbd2e13
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.
@eronisko thanks for the heads-up, I'll update the docs.
fbd2e13
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 met the same problem as @subratpanda1. Still not working in 0.34.0
fbd2e13
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'm getting the same error as @subratpanda1
I'm sorry but this hack affect more bad then good. Please consider revert back.
fbd2e13
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.
@subratpanda1 @XiaoBuu @vyky I found that a module was still using the old API. The error went away after updating the module to use the new API.