//Login class
public class SignIn extends AppCompatActivity {
private EditText mEmail;
private EditText mPassword;
private Button mButton;
private FirebaseAuth mAuth;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Please Wait");
mProgressDialog.setCancelable(false);
setContentView(R.layout.activity_sign_in);
mAuth = FirebaseAuth.getInstance();
mEmail = (EditText) findViewById(R.id.email_login);
mPassword = (EditText) findViewById(R.id.password_login);
mButton = (Button) findViewById(R.id.login_btn);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mProgressDialog.show();
final String email,password;
email = mEmail.getText().toString();
password = mPassword.getText().toString();
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
FirebaseHandler.checkIfDriverExist(email, new DriverExistance() {
@Override
public void onSearchComplete(boolean isFound) {
if(isFound)
{
Toast.makeText(SignIn.this,"Logged In",Toast.LENGTH_SHORT).show();
Log.v("debugMood","Login is found");
startActivity(new Intent(SignIn.this,MainActivity.class));
SignIn.this.finish();
}
else
{
Toast.makeText(SignIn.this,"Complete Your Profile",Toast.LENGTH_LONG).show();
Log.v("debugMood","Login is not found");
startActivity(new Intent(SignIn.this,CompleteProfile.class));
SignIn.this.finish();
}
}
});
}
else
{
Toast.makeText(SignIn.this,"Failed to Login",Toast.LENGTH_SHORT).show();
}
mProgressDialog.dismiss();
}
});
}
});
}
}
、checkIfDriverExist
チェックし、それは、ログインするユーザの初めての場合は、それはそれはMainActivity
に彼を移動し、他の、CompleteProfile
活動に彼を移動しますインタフェース上記のコードで
//Complete profile
public class CompleteProfile extends AppCompatActivity {
private EditText mName;
private EditText mPassword;
private EditText mPlateChars;
private EditText mPlateNums;
private EditText mPhoneNum;
private Button mButton;
private Driver mDriver;
private FirebaseDatabase officeDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complete_profile);
Log.v("debugMood","Complete profile bro");
mDriver = new Driver();
mName = (EditText) findViewById(R.id.driver_name_complete_profile);
mPassword = (EditText) findViewById(R.id.password_complete_profile);
mPlateChars = (EditText) findViewById(R.id.plate_chars_complete_profile);
mPlateNums = (EditText) findViewById(R.id.plate_num_complete_profile);
mPhoneNum = (EditText) findViewById(R.id.driver_phone_number_complete_profile);
mButton = (Button) findViewById(R.id.complete_profile_btn);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDriver.setDriverEmail(FirebaseAuth.getInstance().getCurrentUser().getEmail());
mDriver.setDriverPassword(mPassword.getText().toString());
mDriver.setDriverName(mName.getText().toString());
mDriver.setPlateChars(mPlateChars.getText().toString());
mDriver.setPlateNums(mPlateNums.getText().toString());
Log.v("debugMood","Complete profile before database handler");
FirebaseHandler.completeDriverProfile(mDriver, FirebaseDatabase.getInstance(OfficeApp.officeApp(CompleteProfile.this))
,new com.example.android.er123ambulance.callbacks.CompleteProfile() {
@Override
public void onProfileComplete() {
Log.v("debugMood","Complete profile after database handler");
Toast.makeText(CompleteProfile.this,"Profile Updated",Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
上記のコードはとても基本的に、彼は自分自身について、私が追加したfirebase
に送信するより多くのデータを追加し、ユーザーはそれがログインする彼の最初の時間だときにリダイレクトされます活動ですいくつかのLogcats OコードとCompleteProfile
活動のいくつかの理由のAndroidメーカー
//Logs order
01-29 06:33:09.775 6341-6341/com.example.android.er123ambulance V/debugMood: Login is not found
01-29 06:33:10.635 6341-6341/com.example.android.er123ambulance V/debugMood: Complete profile bro
01-29 06:33:49.445 6341-6341/com.example.android.er123ambulance V/debugMood: Complete profile before database handler
01-29 06:33:49.675 6341-6341/com.example.android.er123ambulance V/debugMood: Login is found
01-29 06:33:56.775 6341-6341/com.example.android.er123ambulance V/debugMood: Complete profile after database handler
01-29 06:37:50.775 6341-6341/com.example.android.er123ambulance V/debugMood: Login is found
によって示されるように、私はlogcatsの順序を投稿しますの下に、コードを実行した後に奇妙な行動に気づいた、ユーザーがに戻ってリダイレクトされますSignIn
というアクティビティがあるので、ユーザが初めてログインしたかどうかを確認します。if条件がtrueを返してユーザがMainActivity
に移動する理由はわかりません。