• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Camera X, LifecycleOwner ... "Cannot be cast to..."

Nightpoison

Newbie
So I'm working with Camerax, new to Android development, and I'm attempting to write an application that takes an image on a specific event, not button related, without having to pull up the camera application. I have it all working, but my MainActivity is overloaded. So to clean up the MainActivity.java file I decided to offload different aspects to other files. Such as normal OOP concept.

So I created a CameraFuncs.java file. Which I setup a constructor that I passed an object of the MainActivity class so I can access all the UI objects.

Java:
public class CameraFuncs
{
    MainActivity main;

    public CameraFuncs(MainActivity mainActivity)
    {
        main = mainActivity;
  ...
  ...
  ...
     }
}

my orientation listener works just fine. I have access to UI objects. Everything seems to be working just fine. Execpt when I attempt to bindtolifecycle(). It throws an error.

Java:
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) this, cameraSelector,
                main.imageCapture);

I get the following error

upload_2020-8-12_10-41-32.png


I'm not really understanding whats going on with bind to lifecycle. Can something clarify whats happening here, point me in the right direction?
 
Back
Top Bottom