javaandroidfirebasefirebase-authenticationfirebase-app-indexing

Unable to call method FirebaseApp.delete()


I'm trying to remove the secondaryApp code as I wanted to prevent the function firebaseAuth.createUserWithEmailAndPassword(email,password) to automatically sign in after user creation

I've referenced the code below:

FirebaseOptions.Builder fbo = new FirebaseOptions.Builder();
    fbo.setApiKey("YOUR_WEB_API_KEY");
    fbo.setDatabaseUrl("https://[YOUR_PROJECT_ID].firebaseio.com/");
    fbo.setProjectId("YOUR_PROJECT_ID");
    fbo.setApplicationId("YOUR_APP_ID"); //Tested, App Id is required.
    FirebaseOptions firebaseOptions = fbo.build();
    final FirebaseApp secondaryAuth = FirebaseApp.initializeApp([JAVA_CLASS_NAME].this, firebaseOptions, "secondary_db_auth");

And it works, however when I'm attempting to invoke the method

secondaryAuth.delete()

it returns an error stating the method cannot be invoked, just as the image below states.

Error image

I've checked the documentation from firebase [FirebaseApp.delete()][2] and expecting it to work however it is not. Everything else works out its just the delete() not working

https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/FirebaseApp

The whole code implementation is as below:

private void CreateAccount() {
        String name = username.getText().toString();
        String phone = phoneNumber.getText().toString();
        String email = emailAddress.getText().toString();
        String password = passwordTxt.getText().toString();
        String confirmPassword = confirmPasswordTxt.getText().toString();
        String points = pointsTransfer.getText().toString();
        final DatabaseReference RootRef;
        final FirebaseAuth firebaseAuth;

        FirebaseOptions.Builder fbo = new FirebaseOptions.Builder();
        fbo.setApiKey("YOUR_WEB_API_KEY");
        fbo.setDatabaseUrl("https://[YOUR_PROJECT_ID].firebaseio.com/");
        fbo.setProjectId("YOUR_PROJECT_ID");
        fbo.setApplicationId("YOUR_APP_ID"); //Tested, App Id is required.
        FirebaseOptions firebaseOptions = fbo.build();
        final FirebaseApp secondaryAuth = FirebaseApp.initializeApp([JAVA_CLASS_NAME].this, firebaseOptions, "secondary_db_auth");

        RootRef = FirebaseDatabase.getInstance().getReference().child("Users");
        firebaseAuth = FirebaseAuth.getInstance(secondaryAuth);


        if(TextUtils.isEmpty(name)){
            Toast.makeText(this, "Please insert your user name.", Toast.LENGTH_SHORT).show();
        }
        else if(TextUtils.isEmpty(phone)){
            Toast.makeText(this, "Please insert your phone number.", Toast.LENGTH_SHORT).show();
        }
        else if(TextUtils.isEmpty(email)){
            Toast.makeText(this, "Please insert your phone number.", Toast.LENGTH_SHORT).show();
        }
        else if(TextUtils.isEmpty(password)){
            Toast.makeText(this, "Please insert your password.", Toast.LENGTH_SHORT).show();
        }
        else if(TextUtils.isEmpty(confirmPassword)){
            Toast.makeText(this, "Please insert your password again.", Toast.LENGTH_SHORT).show();
        }
        else if(!password.equals(confirmPassword)){
            Toast.makeText(this, "Password does not match.", Toast.LENGTH_SHORT).show();
        }
        else if(TextUtils.isEmpty(points)){
            Toast.makeText(this, "You need to send some points", Toast.LENGTH_SHORT).show();
        }
        else if(Float.parseFloat(currentUser.getPoints())<Float.parseFloat(points)){
            Toast.makeText(this, "You do not have sufficient points.", Toast.LENGTH_SHORT).show();
        }
        else{
            loadingBar.setTitle("Create Account");
            loadingBar.setMessage("Please wait, we are checking the credentials.");
            loadingBar.setCanceledOnTouchOutside(false);
            loadingBar.show();

            ValidateAccount(name, phone,email, password, confirmPassword,points, RootRef, firebaseAuth);
            secondaryAuth.delete();
        }
    }

Solution

  • There is no method FirebaseApp.delete() as far as I can see in the reference documentation.

    Once you've created a FirebaseApp instance, it will exist for the life time of that app. Given that FirebaseApp instances are quite lightweight, that shouldn't usually be a problem.

    But they can of course be holding on to more expensive resources such as the service instances. If that is a concern for your app, be sure to isolate the usage of the names app instances and their services, so that they can be garbage collection once they're no longer needed.


    It sounds like you want to detect if you're already initialized the FirebaseApp, which you can do by calling getApps(), looping through the results and checking the name of each. Alternatively you can call getInstance("secondary_db_auth") and handle the exception it throws when the app instance doesn't exist yet.