question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lifecycle binding

See original GitHub issue

in CameraFragment you call

CameraX.bindToLifecycle(this, preview, imageCapture, imageAnalyzer)

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 call CameraX.unbindAll() which is some sort of work around. Instead it would be better to call CameraX.bindToLifecycle() with viewLifecycleOwner. Then you can delete CameraX.unbindAll()

Thus, it seems like you have misused fragment’s lifecycle with view’s lifecycle. Correct me I am wrong. Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BulatMukhutdinovcommented, Jun 7, 2019

Could you please explicitly specify where in the sample CameraX *initialize* happens?

1reaction
owahltinezcommented, Jun 6, 2019

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 CameraFragment sets the retainInstance flag.

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: CameraX.unbindAll()CameraX.bindToLifecycle(), which happens during onViewCreated.

By using the view’s lifecycle, the order of events is: CameraX *teardown*CameraX *initialize*CameraX.bindToLifecycle(). However, I just tested this and it seems that this results in snappier transitions during device rotations on a Pixel 3 device. I’m guessing it’s due to the teardown starting as the view gets destroyed, rather than doing everything during onViewCreated.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bind layout views to Architecture Components
The layouts in your app can bind to the data in the Architecture Components, which already help you manage the UI controllers lifecycle...
Read more >
Handling Lifecycle with View Binding in Fragments - Medium
View Binding is an upcoming feature in Android, available in Android Studio 3.6 Canary 11+ which allows you to more easily interact with...
Read more >
Binding lifecycle events - Knockout.js
Binding lifecycle events · childrenComplete — This event is notified synchronously once the child nodes (and all synchronously loaded descendants) have been ...
Read more >
Introduction to the Build Lifecycle - Apache Maven
Each packaging contains a list of goals to bind to a particular phase. For example, the jar packaging will bind the following goals...
Read more >
Lifecycle of Binding Templates - Documentation - SAPUI5 SDK
The lifecycle of the binding templates differs from the lifecycle of controls that are contained in an aggregation. Whenever a control object is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found