Android - onActivityCreated never called on detached project
See original GitHub issueI’m trying to use https://github.com/wix/react-native-keyboard-input in my detached android (exp detach) project and it’s not working but the project that created by $ react-native init
does.
So I diged into the android project and found out that the onActivityCreated
method of Application.ActivityLifecycleCallbacks
never called.
Here the code:
public class KeyboardInputPackage implements ReactPackage {
public KeyboardInputPackage(Application application) {
application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
sCurrentActivity = activity; // never trigger
}
@Override
public void onActivityStarted(Activity activity) {
sCurrentActivity = activity; // trigger when I turn off the screen then turn on again
}
.....
})
}
}
The onActivityCreated
never trigger make the module entirely not working.
How can I fix it?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top Results From Across the Web
onActivityCreated is always called? - Stack Overflow
Most methods of the host Activity are mirrored by Fragments. onRestart() called when your Activity in a back stack and you hit back...
Read more >Fragment lifecycle - Android Developers
The onDetach() callback is invoked when the fragment has been removed from a FragmentManager and is detached from its host activity.
Read more >Deprecate Fragment's onActivityCreated() [144309266]
We should deprecate onActivityCreated(), citing that the method is called directly after onViewCreated() and is not a one time call immediately after the ......
Read more >core/java/android/app/Fragment.java - platform/frameworks/base ...
<li> {@link #onActivityCreated} tells the fragment that its activity has ... is called when this Fragment is attached or detached when not popping...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is that in Expo app (even after detaching)
ExponentActivity
extends fromReactNativeActivity
, which is something defined by Expo SDK.Meanwhile, apps created with
react-native init
hasThe way
ReactNativeActivity
handles activity events are very different fromReactActivity
. It will not call the methods defined and passed inaddActivityEventListener
That means, the official way to create call back in android bridge, as it is documented here https://facebook.github.io/react-native/docs/native-modules-android.html, will no longer work.
I think this is a big issue as all of the bridge packages that needs callback will not work. Would be great if the author can help address this.
Thanks.
This should be fixed in SDK 24!