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
  • 499,950
  • 69
  • 739
  • 734
aboodrak
  • 843
  • 8
  • 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

1 Answers1

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
  • 843
  • 8
  • 15