1

I'm successfully created user with email from android without any problem but after I downloaded the standard java library and tried to make user I get no error or feedback for error or success in callback

public static void main(String ...args){
    String url= "https://example.firebaseio.com/";
    Firebase fb = new Firebase(url);
    fb.createUser("example@gmail.com", "123456", new Firebase.ResultHandler() {
        @Override
        public void onSuccess() {
            System.out.println("success");
        }
        @Override
        public void onError(FirebaseError firebaseError) {
            System.out.println("failed !");
        }
    });
    System.out.println("Hello there");
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
aboodrak
  • 873
  • 9
  • 15
  • 1
    The main thread is probably quitting before the callback can return. You could check your Firebase account to see if the user is actually created – OneCricketeer May 14 '16 at 14:43
  • Good catch @cricket_007. See http://stackoverflow.com/questions/37098006/firebase-with-java-non-android-retrive-information/37100794#37100794 for more info on this. – Frank van Puffelen May 14 '16 at 15:11
  • @FrankvanPuffelen Thanks, I know RxJava will do the same thing, but there is a blocking mechanism in that API. Not sure about Firebase – OneCricketeer May 14 '16 at 15:15

2 Answers2

0

as above comments , the problem is the main thread is exit before ResultHnadler get called so i fixed the problem in this way to prevent the main thread terminate before the ResultHnadler get called its nice if there is better way

 public static void main(String ...args)  {
    final AtomicBoolean isCalled = new AtomicBoolean(false);
    String FIREBASE = "https://example.firebaseio.com/";
    Firebase fb = new Firebase(FIREBASE);
    fb.createUser("testtesttest@gmail.com", "1234321", new Firebase.ResultHandler() {
        @Override
        public void onSuccess() {
            isCalled.set(true);
            System.out.println("success");
        }
        @Override
        public void onError(FirebaseError firebaseError) {

            isCalled.set(true);
            System.out.println("fail");
        }
    });
    while (!isCalled.get()){
    }
}
aboodrak
  • 873
  • 9
  • 15
0

If u are using an emulator to run your code just wait for 20-30 minutes,Because nowadays takes that much time,else you can use a device:it is much faster

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 04 '22 at 17:28