Guest User

MainActivity

a guest
Jan 7th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. package com.example.student.first_machlakot;
  2.  
  3. import android.support.annotation.NonNull;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. import com.google.android.gms.tasks.OnCompleteListener;
  13. import com.google.android.gms.tasks.Task;
  14. import com.google.firebase.auth.AuthResult;
  15. import com.google.firebase.auth.FirebaseAuth;
  16. import com.google.firebase.auth.FirebaseUser;
  17.  
  18. public class MainActivity extends AppCompatActivity {
  19.  
  20.     private FirebaseAuth mAuth;
  21.     Button btn;
  22.     EditText etMail, etPass;
  23.     String email, password;
  24.  
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.activity_main);
  29.  
  30.         etMail = findViewById(R.id.etMail);
  31.         etPass = findViewById(R.id.etPass);
  32.         btn = findViewById(R.id.btn);
  33.  
  34.         mAuth = FirebaseAuth.getInstance();
  35.  
  36.     }
  37.  
  38.     public void click(View view) {
  39.         email = etMail.getText().toString();
  40.         password = etPass.getText().toString();
  41.  
  42.         mAuth.createUserWithEmailAndPassword(email, password)
  43.                 .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  44.                     @Override
  45.                     public void onComplete(@NonNull Task<AuthResult> task) {
  46.                         if (task.isSuccessful()) {
  47.                             // Sign in success, update UI with the signed-in user's information
  48.                             Log.d("TAGsucce", "createUserWithEmail:success");
  49.                             FirebaseUser user = mAuth.getCurrentUser();
  50.  
  51.                         } else {
  52.                             // If sign in fails, display a message to the user.
  53.                             Log.w("failed", "createUserWithEmail:failure", task.getException());
  54.                             Toast.makeText(MainActivity.this, "Authentication failed.",
  55.                                     Toast.LENGTH_SHORT).show();
  56.                         }
  57.  
  58.  
  59.                     }
  60.                 });
  61.     }
  62. }
Add Comment
Please, Sign In to add comment