Navigation box does not work when startActivity is used in the first case of selectItem

I have this problem with Google Navigation Drawer, where the start of the activity specified in the first case (case 0) in my selectItem method is interrupted and returns to the previous action.

private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectItem(position); } } private void selectItem(int position) { switch(position) { case 0: // Placing any startActivity here will load the activity // but immediately return to the calling activity. parent.startActivity(new Intent(parent, Dashboard.class)); break; case 1: parent.startActivity(new Intent(parent, Card.class)); break; } } 

But if I put mDrawerLayout.closeDrawer(mDrawerList); or any other code, it will work fine.

No errors are reported when the called activity is closed and no exception is thrown. Any thoughts?

+4
source share
1 answer

I tried to reproduce this, and he will not decide the parent. Did you announce it somewhere else?

In which class you use this in both actions and fragments, you can use startActivity () without the need for parent.startActivity ()

Can you post a full class?

This works for me well.

 private void selectItem(int position) { switch (position) { case 0: // goto home screen Log.d(TAG, "Showing Home"); startActivity(new Intent(this, SettingsActivity.class)); break; case 1: // Show Editor Log.d(TAG, "Showing Editor"); break; default: break; } } 
0
source

Source: https://habr.com/ru/post/1497175/


All Articles