'Home activity with nav drawer menu does not open after login
I created a Login android app, connected to firebase Real time database and works perfectly (Users has been created successfully).
From LoginActivity, users must go to HomeActivity, which has a navigation drawer menu, but does not work.
I tried to change the activity destination, so after login, I tried to open a TrialActivity and works perfectly.
What could be the problem?
LoginActivity
public class LoginActivity extends AppCompatActivity {
private EditText InputNumber, InputPaswd;
private Button LoginBtn;
private ProgressDialog loadingBar;
private String parentDBName = "Users";
private TextView AdminLink, NotAdminLink;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
InputNumber = (EditText) findViewById(R.id.login_phone_numb_input);
InputPaswd = (EditText) findViewById(R.id.login_Password);
LoginBtn = (Button) findViewById(R.id.login_btn);
loadingBar = new ProgressDialog(this);
AdminLink = (TextView) findViewById(R.id.admin_panel_link);
NotAdminLink = (TextView) findViewById(R.id.not_admin_panel_link);
LoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LoginUser();
}
});
AdminLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LoginBtn.setText("Login Admin");
AdminLink.setVisibility(View.INVISIBLE);
NotAdminLink.setVisibility(View.VISIBLE);
parentDBName="Admins";
}
});
NotAdminLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LoginBtn.setText("Login");
AdminLink.setVisibility(View.VISIBLE);
NotAdminLink.setVisibility(View.INVISIBLE);
parentDBName="Users";
}
});
}
private void LoginUser() {
String phone = InputNumber.getText().toString();
String password = InputPaswd.getText().toString();
// InputNumber.setText("3791881336");
//InputPaswd.setText("1234");
if (TextUtils.isEmpty(phone)) {
Toast.makeText(this,"Please enter your number",Toast.LENGTH_SHORT);
}
else if (TextUtils.isEmpty(password)){
Toast.makeText(this,"Please enter your password",Toast.LENGTH_SHORT);
}
else {
loadingBar.setTitle("Log in");
loadingBar.setMessage("Please wait, loading");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
AllowAccessToAccount( phone, password);
}
}
private void AllowAccessToAccount(String phone, String password) {
final DatabaseReference RootRef;
DatabaseReference reference = FirebaseDatabase.getInstance( "https://ecommerce-bdb44-default-rtdb.europe-west1.firebasedatabase.app").getReference();
RootRef = FirebaseDatabase.getInstance().getReference();
RootRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.child(parentDBName).child(phone).exists()){
Users userData = snapshot.child(parentDBName).child(phone).getValue(Users.class);
if (userData.getPhone().equals(phone)){
if (userData.getPassword().equals(password)){
if (parentDBName.equals("Admins")){
Toast.makeText(LoginActivity.this, "Logged in Successfully", Toast.LENGTH_SHORT);
loadingBar.dismiss();
Intent intent = new Intent(LoginActivity.this, AdminActivity.class);
startActivity(intent);
}
else if
(parentDBName.equals("Users")){
Toast.makeText(LoginActivity.this, "Logged in Successfully", Toast.LENGTH_SHORT);
loadingBar.dismiss();
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(intent);
}
}
}
}
else {
Toast.makeText(LoginActivity.this, "Account with" + phone + "do not exist",Toast.LENGTH_SHORT);
loadingBar.dismiss();
Toast.makeText(LoginActivity.this, "You need to create an account",Toast.LENGTH_SHORT);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
