0

A large percentage of examples that I find online inherit from AppCompatActivity rather than Activity. Is this really what I should be doing? I have heard that Activity is newer, and it is my preference. I am currently attempting to learn to use CameraX, and there are very few examples & support that I have been able to find for Xamarin.Android. After finding the following Android tutorial & a translation of it for Xamarin.Android:

https://developer.android.com/codelabs/camerax-getting-started

https://github.com/DottorPagliaccius/Xamarin.CameraX

However, the first parameter of BindToLifecycle seems to like AppCompatActivity but not Activity. Does anybody know what changes I need to make in order to be able to use Activity instead of AppCompatActivity?

1 Answers1

0

Actually, AppCompatActivity is newer than Activity. AppCompatActivity supports some of the newer platform features on older Android devices. Some of these backported features include: Using the action bar, including action items, navigation modes and more with the setSupportActionBar(Toolbar) API.

But don't be worry about trouble of using AppCompatActivity.It's similar to usage of Activity. You said that the first parameter of BindToLifecycle seems to like AppCompatActivity but not Activity. In fact, you can treat it like Activity to use.

        // Bind use cases to camera
        cameraProvider.BindToLifecycle.
        (this, cameraSelector, preview, imageCapture, imageAnalyzer);

For more details about AppCompatActivity and Activity, you can check: https://stackoverflow.com/questions/31297246/activity-appcompatactivity-fragmentactivity-and-actionbaractivity-when-to-us#:~:text=The%20differences%20between%20them%20are%3A%20Activity%20is%20the,Based%20on%20FragmentActivity%2C%20AppCompatActivity%20provides%20features%20to%20ActionBar.

Jianwei Sun - MSFT
  • 2,289
  • 1
  • 3
  • 7
  • Are you suggesting that I use `AppCompatActivity` instead of `Activity`? – Nathan Sokalski Sep 07 '22 at 19:02
  • It depends. `CameraX` using `AndroidX` namespace, that's to say your project has to use `AppCompatActivity` . Another example , you want `Fragement`, you can derive from `FragementActivity`. – Jianwei Sun - MSFT Sep 08 '22 at 05:43
  • If I cannot use `CameraX` in `Activity`, then I will probably just try to use `Camera2` directly rather than attempt to convert all my stuff to `AppCompatActivity` (there isn't anything in `Camera2` that can't be done with `Activity` is there?). – Nathan Sokalski Sep 09 '22 at 15:21
  • I tried to add reference about `Camera2` by NuGet, but search results show that Xamarin.AndroidX.Camera.Camera2 package by Microsoft. – Jianwei Sun - MSFT Sep 13 '22 at 03:11