0

My application has a navigation drawer. From drawer options, I am opening different activities. At that time a blank screen is displayed before the new Activity.

@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) {

switch (item.getItemId()) {
    case R.id.nav_message:

        Intent newAct = new Intent(getApplicationContext(), FeedbackActivity.class);
        startActivity(newAct);
    
       break;


}


drawer.closeDrawer(Gravity.RIGHT);
return true;

}

As per some investigations, I found like we need to remove the below code from this. Tried the same and working fine.

drawer.closeDrawer(Gravity.RIGHT);
    return true;

But when I click the back button from the new activity, the drawer is still open status. How can I close without that black screen?

Malhotra
  • 221
  • 3
  • 13

2 Answers2

1

Have you tried passing GRAVITY.START as a parameter to drawer.close(int gravity), like this:

switch (item.getItemId()) {
    case R.id.nav_message:

        Intent newAct = new Intent(getApplicationContext(), FeedbackActivity.class);
        startActivity(newAct);
    
       break;


}



drawer.closeDrawer(GravityCompat.START);
return true;

And don't forget to initialize the drawer object with findViewById()

Yousha Arif
  • 1,188
  • 8
  • 20
  • 1
    Thanks a lot. I initialized the drawer object as final. Issue fixed by removing final declaration. – Malhotra Apr 14 '21 at 06:19
1

Try to disable drawer menu animation and call closeDrawer before starting new activity

    drawer.closeDrawer(Gravity.RIGHT, false);
    switch (item.getItemId()) {
    case R.id.nav_message:

        Intent newAct = new Intent(getApplicationContext(), FeedbackActivity.class);
        startActivity(newAct);
    
       break;


}

return true;