public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {  
   private AppBarConfiguration mAppBarConfiguration;  
    private DatabaseReference ProductsRef;  
    private RecyclerView recyclerView;  
    RecyclerView.LayoutManager layoutManager;  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_home);  
        ProductsRef = FirebaseDatabase.getInstance().getReference().child("Products");  
        Paper.init(this);  
        Toolbar toolbar = findViewById(R.id.toolbar);  
        toolbar.setTitle("Home");  
        setSupportActionBar(toolbar);  
        FloatingActionButton fab = findViewById(R.id.fab);  
        fab.setOnClickListener(new View.OnClickListener() {  
            @Override  
            public void onClick(View view) {  
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)  
                        .setAction("Action", null).show();  
        DrawerLayout drawer = findViewById(R.id.drawer_layout);  
        NavigationView navigationView = findViewById(R.id.nav_view);  
        View headerView = navigationView.getHeaderView(0);  
        TextView userNameTextView = headerView.findViewById(R.id.user_profile_name);  
        CircleImageView profileImageView = headerView.findViewById(R.id.user_profile_image);  
        userNameTextView.setText(Prevalent.currentOnlineUser.getName());  
        // Passing each menu ID as a set of Ids because each  
        // menu should be considered as top level destinations.  
        mAppBarConfiguration = new AppBarConfiguration.Builder(  
                R.id.nav_cart, R.id.nav_categories, R.id.nav_logout,R.id.nav_settings, R.id.nav_orders, R.id.nav_home)  
                .setOpenableLayout(drawer)  
                .build();  
        //NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_home);  
        //NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);  
        //NavigationUI.setupWithNavController(navigationView, navController);  
        recyclerView = findViewById(R.id.recycler_menu);  
        recyclerView.setHasFixedSize(true);  
        layoutManager = new LinearLayoutManager(this);  
        recyclerView.setLayoutManager(layoutManager);  
    @Override  
    protected void onStart() {  
        super.onStart();  
        FirebaseRecyclerOptions<Products> options =  
                new FirebaseRecyclerOptions.Builder<Products>()  
                .setQuery(ProductsRef,Products.class)  
                .build();  
        FirebaseRecyclerAdapter<Products, ProductViewHolder> adapter =  
                new FirebaseRecyclerAdapter<Products, ProductViewHolder>(options) {  
                    @Override  
                    protected void onBindViewHolder(@NonNull ProductViewHolder holder, int position, @NonNull Products model) {  
                        holder.txtProductName.setText(model.getPname());  
                        holder.txtProductDescription.setText(model.getDescription());  
                        holder.txtProductPrice.setText("Price = "+ model.getPrice());  
                        Picasso.get().load(model.getImage()).into(holder.imageView);  
                    @NonNull  
                    @Override  
                    public ProductViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {  
                        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_items_layout, parent, false);  
                        ProductViewHolder holder = new ProductViewHolder(v);  
                        return holder;  
            recyclerView.setAdapter(adapter);  
            adapter.startListening();  
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        // Inflate the menu; this adds items to the action bar if it is present.  
        getMenuInflater().inflate(R.menu.home, menu);  
        return true;  
    //@Override  
    //public boolean onSupportNavigateUp() {  
        //NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_home);  
        //return NavigationUI.navigateUp(navController, mAppBarConfiguration)  
                //|| super.onSupportNavigateUp();  
    @Override  
    public boolean onOptionsItemSelected(MenuItem item){  
        int id = item.getItemId();  
        return super.onOptionsItemSelected(item);  
    @SuppressWarnings("StatementWithEmptyBody")  
    @Override  
    public boolean onNavigationItemSelected(MenuItem item) {  
        int id = item.getItemId();  
        if (id == R.id.nav_cart) {  
        } else if (id == R.id.nav_orders) {  
        } else if (id == R.id.nav_categories) {  
        } else if (id == R.id.nav_settings) {  
            Intent intent = new Intent(HomeActivity.this,settinsActivity.class);  
            startActivity(intent);  
        } else if (id == R.id.nav_logout) {  
            Paper.book().destroy();  
            Intent intent = new Intent(HomeActivity.this,MainActivity.class);  
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);  
            startActivity(intent);  
            finish();  
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);  
        drawer.closeDrawer(GravityCompat.START);  
        return true;  

this is the image and the code of the HomeActivity.java actually i'm doing a tutorial and i found some difficult because of the new version of android studio i add an Intent as you see in the onNavigationItemSelected(MenuItem item) methode to go to another activity but it doesn't work when i click in the button of the bar like logout or settings can you help me to found the problem please Thanks155971-xfgfgddfgh.png

Hi @Chaymae Benayyad ,

The best place to get assistance with developing your Android app in Android Studio would be either Stackoverflow or the Android Community. Having said that, in looking at the UI docs, I didn't see any specific section using NavigationView. I'm not familiar with the API set but looking at your code, I don't see where the individual menu item has been wired to the event handler. HomeActivity should have child controls that represent the individual menu item, and that child should be wired to the event handler.