Skip to content
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

MainActivity cannot be cast to androidx.fragment.app.FragmentActivity #26827

Closed
woshi82 opened this issue Oct 12, 2019 · 3 comments
Closed

MainActivity cannot be cast to androidx.fragment.app.FragmentActivity #26827

woshi82 opened this issue Oct 12, 2019 · 3 comments
Labels
Bug Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@woshi82
Copy link

woshi82 commented Oct 12, 2019

When i upgrade my APP with react-native 0.60.5 in Android,
My app is integration-with-existing-apps
The problems occurs

2019-10-12 09:57:20.982 18495-18495/com***** E/unknown:ReactNative: Exception in native call
    java.lang.ClassCastException: com*****.MainActivity cannot be cast to androidx.fragment.app.FragmentActivity
        at com.facebook.react.modules.dialog.DialogModule.getFragmentManagerHelper(DialogModule.java:245)
        at com.facebook.react.modules.dialog.DialogModule.onHostResume(DialogModule.java:177)
        at com.facebook.react.bridge.ReactContext.onHostResume(ReactContext.java:208)
        at com.facebook.react.ReactInstanceManager.moveToResumedLifecycleState(ReactInstanceManager.java:661)
        at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:580)
        at com.facebook.react.ReactInstanceManager.onHostResume(ReactInstanceManager.java:536)
        at com.*****.MainActivity.onResume(MainActivity.java:4227)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1355)
        at android.app.Activity.performResume(Activity.java:7154)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3666)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3731)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2937)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1620)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:6704)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)

//  com.*****.MainActivity
public class MainActivity extends NativeActivity implements **** {
  ....
  protected void onResume() {
    .....
    ......
    mReactNativeHost.getReactInstanceManager().onHostResume(this, this);
    ......
  }
}

It's seems like my MainActivity must extends to FragmentActivity, according to this PR. But my activity extends NativeActivity already, and we need it.

Can anyone tell me Why DialogModule supports only FragmentActivity please?
If it must do, can you give me any ideas about how to deal with FragmentActivity and NativeActivity please?

React Native version:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Memory: 7.34 GB / 15.96 GB
Binaries:
Node: 10.16.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.16.0 - D:\soft\Yarn\bin\yarn.CMD
npm: 6.11.3 - C:\Program Files\nodejs\npm.CMD

react-native: 0.60.5
react: 16.8.6

Steps To Reproduce

  1. Follow integration-with-existing-apps to integrate RN with custom android app.
  2. Make MainActivity extends NativeActivity
  3. Run the android App
  4. Error occurs : MainActivity cannot be cast to androidx.fragment.app.FragmentActivity

Describe what you expected to happen:
Expect no such error occurs .

Snack, code example, screenshot, or link to a repository:

#23365
electrode-io/electrode-native#1363

@woshi82 woshi82 added the Bug label Oct 12, 2019
@react-native-bot react-native-bot added the Platform: Android Android applications. label Oct 12, 2019
@gitfdy
Copy link

gitfdy commented Jan 8, 2020

我在打开debug时,有遇到这种情况,目前新版的rn可以在终端查看到打印日志,关闭debug,就不会有这个问题出现了

@stale
Copy link

stale bot commented Apr 7, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 7, 2020
@stale
Copy link

stale bot commented Apr 14, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Apr 14, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants