2017-07-10 68 views
0

主要業務:我的連接到谷歌服務的錯誤在哪裏?

public class MainActivity extends AppCompatActivity implements View.OnClickListener { 

    TextView email; 
    TextView password; 
    TextView sysAnswer; 
    String[] domenArray = {"@gmail.com", "@mail.ru", "@ya.ru", "@yandex.ru", "@yahoo.ru"}; 
    ImageButton enter; 
    ImageButton registration; 
    private FirebaseAuth mAuth; 
    private FirebaseAuth.AuthStateListener mAuthListener; 
    AuthHandler aH = new AuthHandler(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     email = (TextView) findViewById(R.id.email); 
     password = (TextView) findViewById(R.id.password); 
     sysAnswer = (TextView) findViewById(R.id.sysAnswer); 
     mAuth = FirebaseAuth.getInstance(); 


     mAuthListener = new FirebaseAuth.AuthStateListener() { 
      @Override 
      public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { // слушает действия пользователя 
       FirebaseUser user = firebaseAuth.getCurrentUser();    // зашел, вышел и что с этим делать 
       if (user != null) { 
        // User is signed in 
       } else { 
        // User is signed out 
       } 
      } 
     }; 

     findViewById(R.id.registration).setOnClickListener(MainActivity.this); 
     findViewById(R.id.sign_in).setOnClickListener(MainActivity.this); 

    } 


    @Override 
    public void onClick(View v) { 
     if (v.getId() == R.id.registration) { 
      aH.registration(email.getText().toString(), password.getText().toString()); 
      if (v.getId() == R.id.sign_in) { 
       aH.singing(email.getText().toString(), password.getText().toString()); 
       //if (aH.singingResult){ 
       // Toast.makeText(this, "Успешный вход!", Toast.LENGTH_SHORT).show(); 

       //} else { 
       // Toast.makeText(this, "Ошибка! Включите интернет, проверьте правильность форм и попробуйте снова!", Toast.LENGTH_SHORT).show(); 

       //} 
      } 
     } 
    } 
} 

和第二類。

public class AuthHandler { 

    private FirebaseAuth mAuth; 
    private boolean registrationResult = false; 
    private boolean singingResult = false; 


    public void singing(String email, String password) { 
     mAuth.signInWithEmailAndPassword(email, password); 
    } 

    public void registration(String email, String password){ 
     mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() { 
      @Override 
      public void onComplete(@NonNull Task<AuthResult> task) { 
       if(task.isSuccessful()) { 
        registrationResult=true; 
       }else { 
        registrationResult = false; 
       } 
      } 
     }); 
    } 
} 

我已編譯此代碼,但所有時間我的應用程序粉碎後,我點擊按鈕註冊。我想,那個問題用addOnCompleteListener,但我不知道執行程序是什麼意思,或者如何把這個方法帶到一個Activity對象中。你能告訴我我的錯誤嗎? Thx尋求幫助。

+0

什麼是你的日誌? – ashish

回答

0

嘗試在歌唱和登記方法改變,因爲我下面提:

public class AuthHandler { 

    private FirebaseAuth mAuth; 
    private boolean registrationResult = false; 
    private boolean singingResult = false; 


    public void singing(String email, String password) { 
    // mAuth.signInWithEmailAndPassword(email, password); 

      mAuth.getInstance().signInWithEmailAndPassword(email, password); 

    } 

    public void registration(String email, String password){ 
     mAuth.getInstance().createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() { 
      @Override 
      public void onComplete(@NonNull Task<AuthResult> task) { 
       if(task.isSuccessful()) { 
        registrationResult=true; 
       }else { 
        registrationResult = false; 
       } 
      } 
     }); 
    } 
} 
相關問題