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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application crashes on Android 10 (API 29) Samsung Galaxy Note 10 #2

Closed
TomMannson opened this issue Oct 1, 2021 · 3 comments
Closed

Comments

@TomMannson
Copy link

Hi, as I said I will give a try your solution 馃槃
I think I found some problem. I mean reflection.
Generally reflection is bad idea. Statistically object initialization is about 10 times slower then new operator.
But it looks like compose have some additional policy in terms of reflection call inside compose functions

This line is breaking application startup (100% case)
composableInstance.viewmodel = composableResource.viewmodelClass.newInstance() as ViewModel

@JohannRosenberg
Copy link
Owner

JohannRosenberg commented Oct 2, 2021

Hey Tom,

Not sure how your post above got posted into this project because it was originally posted under the older project. Seems like a bug in Github.

Thanks for the feedback. The project you were referring to is deprecated and no longer supported. It has been replaced with Jetmagic:

https://github.com/JohannBlake/Jetmagic

Jetmagic is a far superior framework. As for the issue you raised, I'm not sure what is causing the crash. I use that same line of code in Jetmagic but have never had any issues and have tried it out on a few devices running different OS versions.

Download Jetmagic and run it. If the bug still happens, please let me know by posting the issue in Jetmagic and I'll look into it. It is possible that something else was causing the bug in this project and got corrected in Jetmagic.

As for reflection, that unfortunately is the only way I could create an instance of a class without knowing the class name. The "new" keyword doesn't exist in Kotlin but I know what you mean. As for speed, I don't really see any performance issues, even when running it on older devices.

@TomMannson
Copy link
Author

Ok, tested with Jetmagic and is working 馃憤

As for reflection, that unfortunately is the only way I could create an instance of a class without knowing the class name.
The "new" keyword doesn't exist in Kotlin but I know what you mean. As for speed, I don't really see any performance issues, even when running it on older devices.

Yeah You're right this is only way in runtime but You can use Code generation as an option.
Sadly it is far more complicated but it is much more efficient way to access dynamic code
In early stage of app development there can be no sigh of performance issues.

Maybe You don't need to create viewmodel that way. (I know it is optional)
It has limitation I mean You need to have no parameter constructor which is in most cases insufficient.
It will open also some new ways of initialising vm's by DI libraries like Dagger/Hilt or Koin.

@JohannRosenberg
Copy link
Owner

Jetmagic is still new, so I'm waiting to get some more usage to see how to take it forward. One idea on the viewmodel is to provide a callback in Composable Resource that lets the developer create one however they want. It would also allow them to do DI if want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants