There is a class MainActivity, it has a method
public boolean onNavigationItemSelected(MenuItem item), which is responsible for launching activities or fragments depending on the selected item in the menu. There is one fragment in which you need to transfer the value 1 and 2.
public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentLearnWords fragLearn = new FragmentLearnWords(); Bundle bundle = new Bundle(); if (id == R.id.nav_learn_words) { bundle.putInt("key", 1); ft.replace(R.id.mainFrame, fLearnWords); } else if (id == R.id.nav_repetition_words) { bundle.putInt("key", 2); ft.replace(R.id.mainFrame, fLearnWords); } fragLearn.setArguments(bundle); ft.commit(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } In the snippet, the code is:
Bundle bundle = this.getArguments(); if (bundle != null) { int i = bundle.getInt("key", 0); Toast.makeText(getContext(), ""+i, Toast.LENGTH_SHORT).show(); } Toast is not displayed.
What can be a mistake?
Information taken from this topic