Let's say I have this Function that sets a value in Firebase Database:
    public  void RegisterUserInDB(FirebaseUser user,Profile p,Activity activity){
        DatabaseReference ref= database.getReference("Users");
        ref.child(user.getUid()).setValue(p).addOnCompleteListener(
                new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if(task.isSuccessful()){
                            Toast.makeText(
                                    activity.getApplicationContext()
                                    ,"DB Updated"
                                    ,Toast.LENGTH_LONG)
                                    .show();
                        }
                    }
                }
        );
        dbProfile=p;
        localProfile=p;
    }
I want to use that function somewhere else like this:
RegisterUserInDB(user,p,activity);
doSomeThingAfter();
but I want everything to wait till that task inside the function finishes, I understand that I'm only adding a listener here but not running the task, but as mentioned earlier, something depends on the code I'll put in the onComplete method. Can someone help :)?
Also, do you think it's a bad use to pass the Activity as a parameter?
Every time I do that, the function doSomeThingAfter() executes before the task is done.