So im currently making an app and im using side menu for some features like logout, settings etc. Tho When the user needs to logout i have to redirect him to LoginActivity and for some reason it just closes the side menu like there is nothing on that item. I've looked for similar problems here and on youtube but nothing helps the situation.Also the app seems to have no errors when the "logout_btn" on side menu is pressed
MainActivity:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private BottomNavigationView bottomNav;
private DrawerLayout root;
private Toolbar toolbar;
private TextView report_btn;
private NavigationView navigationView;
private String[] permissions;
private LocationManager locationManager;
private FirebaseAuth mAuth;
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()){
case R.id.logout_btn:
mAuth.signOut();
startActivity(new Intent(MainActivity.this, LoginActivity.class));
break;
}
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Making sure no data are left
ServiceSharedInfo.deleteALlData();
mAuth = FirebaseAuth.getInstance();
//Setting values
FirebaseUser user = mAuth.getCurrentUser();
if(user == null){
startActivity(new Intent(MainActivity.this, LoginActivity.class));
}else{
System.out.println("#~#~#~#~#~#~# User: "+ user.getEmail());
}
permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.INTERNET};
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
root = findViewById(R.id.root_layout);
toolbar = findViewById(R.id.main_tool_bar);
navigationView = findViewById(R.id.side_nav);
bottomNav = findViewById(R.id.bottom_navigation);
bottomNav.setOnNavigationItemSelectedListener(navListener);
report_btn = findViewById(R.id.report_btn);
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(MainActivity.this,
root,toolbar,R.string.navigation_open,
R.string.navigation_close);
root.addDrawerListener(toggle);
toggle.syncState();
getSupportFragmentManager().beginTransaction().replace(R.id.container_layout,
new HomeFragment()).commit();
bottomNav.getMenu().getItem(1).setChecked(true);
report_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"someemil@email.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "<-Your subject here->");
emailIntent.putExtra(Intent.EXTRA_TEXT, "<-Your Problem here->");
startActivity(Intent.createChooser(emailIntent,"Send mail..."));
}
});
navigationView.setNavigationItemSelectedListener(this::onNavigationItemSelected);
}
private BottomNavigationView.OnNavigationItemSelectedListener navListener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragmentSelected = null;
switch(item.getItemId()){
case R.id.home_nav:
fragmentSelected = new HomeFragment();
break;
case R.id.installation_nav:
fragmentSelected = new InstallationFragment();
break;
case R.id.damage_nav:
fragmentSelected = new DamageFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.container_layout,
fragmentSelected).commit();
return true;
}
};
}
activity_main:
android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/root_layout"
android:fitsSystemWindows="true">
side_nav_menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group>
<item
android:id="@+id/logout_btn"
android:title="Log out :("
android:icon="@drawable/ic_baseline_exit_to_app_24"/>
</group>
</menu>
