-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Lifecycle binding #19
Comments
I'm not sure what you mean by "the old lifecycleOwner". The current sample is using the fragment's lifecycle, which usually is the same as the view's lifecycle except By attaching CameraX to the fragment lifecycle, we avoid CameraX being fully torn down (and thus closing the camera) upon config changes like rotation. The intent is to allow for CameraX to maintain some of its state by doing: By using the view's lifecycle, the order of events is: I will investigate the potential implications of switching to the view's lifecycle. It's likely that devices with slow camera open/close will have degraded performance using this path. We have to take into consideration other things such as navigation, multi-window environments, etc. |
Could you please explicitly specify where in the sample |
CameraX initialization is not triggered by app code. Some of it happens upon app startup, some of it when the first use case is bound. It's up to the CameraX library and subject to change in the future. |
Then, returning to original question, it seems that if you would bind to fragment's lifecycle the call stack is The main concern is when you doing |
I don't think this is entirely true. I'm counting camera open as
That's fair feedback, although only partly true. We are just making sure that no other use cases are bound, which is not necessarily a bad practice but, as you say, it kinda defeats the point of making everything lifecycle-aware. As I said earlier, we will investigate switching to using the view's lifecycle as the owner. Personally, assuming there are no major drawbacks, I think it would be the right choice. It simplifies the code and sets a good example for developers to follow. Otherwise, we are chasing diminishing returns for a slight performance gain, whereas some of the optimizations could be done by CameraX itself. For example, CameraX could wait a bit to close the camera during a config change, since it's likely that an app will bind the same use cases and open the same camera again. |
Thank you for your response. I close the issue but pls ping me if there would be any updates on this |
in CameraFragment you call
meaning you bind it to fragment's lifecycle. But you call this method on
onViewCreated()
which means you would receive the old lifecycleOwner. To avoid crashing you every time also callCameraX.unbindAll()
which is some sort of work around.Instead it would be better to call
CameraX.bindToLifecycle()
with viewLifecycleOwner. Then you can deleteCameraX.unbindAll()
Thus, it seems like you have misused fragment's lifecycle with view's lifecycle. Correct me I am wrong.
Thanks
The text was updated successfully, but these errors were encountered: