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

KMM Compose Android Error: "ClassCastException: com.example.app.MainActivity cannot be cast to androidx.fragment.app.FragmentActivity" #106

Closed
Stonerub opened this issue Mar 10, 2024 · 4 comments · Fixed by #114
Labels
bug Something isn't working
Milestone

Comments

@Stonerub
Copy link

Hi, got issue in kmm compose, on android, BindEffect() call this exception:
ClassCastException: com.example.app.MainActivity cannot be cast to androidx.fragment.app.FragmentActivity

iOS works great, without errors. My compose code:

    val factory: PermissionsControllerFactory = rememberPermissionsControllerFactory()

    val viewModel = getViewModel(
        key = "app viewModel",
        factory = viewModelFactory { AppViewModel(
            databaseDriverFactory,
            factory.createPermissionsController()
        ) }
    )

    BindEffect(viewModel.permissionsController)

Using moko mvvm. ViewModel permission calling:

init {
        viewModelScope.launch {
            permissionsController.providePermission(Permission.REMOTE_NOTIFICATION)
        }
}
@Tingel24
Copy link

I have the same problem

@mojtaba-amiri
Copy link

Apparently it's about the MainActivity being ComponentActivity and not FragmentActivity. Changing it to FragmentActivity would be a workaround until Moko team fixes the issue.

@Stonerub
Copy link
Author

Stonerub commented Mar 12, 2024

Apparently it's about the MainActivity being ComponentActivity and not FragmentActivity. Changing it to FragmentActivity would be a workaround until Moko team fixes the issue.

Thank's, it works for me

@Alex009 Alex009 added this to the 0.18.0 milestone Apr 11, 2024
@Alex009 Alex009 added the bug Something isn't working label Apr 11, 2024
@ZiXOps
Copy link

ZiXOps commented Apr 12, 2024

For now developer must use FragmentActivity as root activity to be able display permission dialogs with fragmentManager. I think in future we can change request permissons approach to rememberLauncherForActivityResult for compose apps.

@Alex009 Alex009 linked a pull request Apr 15, 2024 that will close this issue
ZiXOps pushed a commit to ZiXOps/moko-permissions that referenced this issue Apr 18, 2024
ZiXOps pushed a commit to ZiXOps/moko-permissions that referenced this issue Apr 18, 2024
ZiXOps pushed a commit to ZiXOps/moko-permissions that referenced this issue Apr 18, 2024
@Alex009 Alex009 closed this as completed Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants