I am actually new to android studio , Now I am stuck on this Compilation error. Please help.. Following is the problem FragmentActivity activity = this(); Shows Compilation error

Incompatible types

Required: androidx.fragment.app.FragmentActivity

Found: com.example.androidapp.MainActivity

I have used the getSupportFragementManager() and getFragementManager() ..None of this works..

Relevant Code

package com.example.androidapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import androidx.biometric.BiometricPrompt;
import android.os.Bundle;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import androidx.fragment.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;

   public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getName();

    protected void onCreate(Bundle savedInstanceState) {

//Create a thread pool with a single thread//

        Executor newExecutor = Executors.newSingleThreadExecutor();

        FragmentActivity activity = this;

//Start listening for authentication events//

        final BiometricPrompt myBiometricPrompt = new BiometricPrompt(activity, newExecutor, new BiometricPrompt.AuthenticationCallback() {

1 Answers

Martin Zeitler On Best Solutions

Change the imports & signature:

// import android.support.v7.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

public class MainActivity extends FragmentActivity {

Also see Migrating to AndroidX for further replacement packages ...

because mixing up android.support with androidx is problematic.