title: Call Activity from Action Bar menu item click
body: <p>I have 1 Fragment and 2 activities: <code>HomeFragment</code>, <code>ProductActivity</code>, and <code>CartActivity</code>. I want to call <code>CartActivity</code> whenever I click on the cart in the menu. But when I tap on 1 product in <code>HomeFrament</code>, my app calls <code>ProductActivity</code> and <code>CartActivity</code> under <code>ProductActivity</code>.</p>
  
  <p>I am using implementation <code>androidx.appcompat:appcompat:1.0.2</code>.</p>
  
  <p>In Product.java, I call Cart Activity in onOptionsItemSelected</p>
  
  <pre><code>// Click on option button.
  @Override
  public boolean onOptionsItemSelected(@NonNull MenuItem item) {
      int id = item.getItemId();
  
      switch (id){
          case android.R.id.home: {
              this.finish();
          }
          case R.id.app_bar_cart: {
              Log.d(TAG,"Cart Clicked");
              Intent intent = new Intent(this, Cart.class);
              //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity(intent);
              return true;
          }
      }
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>My manifest file:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      package="com.project.coconuc"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;application
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"
          tools:ignore="GoogleAppIndexingWarning"&gt;
          &lt;activity android:name=".Cart"/&gt;
          &lt;activity android:name=".product" /&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>onClick call products</p>
  
  <pre><code>    @Override
      public void onClick(Integer position) {
          Intent callProductActivity = new Intent(mfragment.getActivity(), product.class);
          callProductActivity.putExtra("variable", position.toString());
          Objects.requireNonNull(mfragment.getActivity()).startActivity(callProductActivity);
      }
  </code></pre>
  
  <p>For more details, please see this image: <a href="https://ibb.co/mFFZC30" rel="nofollow noreferrer">https://ibb.co/mFFZC30</a></p>
  
  <p>This is my code:
  <a href="https://github.com/KhoaChau0594/MoblileAppProject/tree/temp" rel="nofollow noreferrer">https://github.com/KhoaChau0594/MoblileAppProject/tree/temp</a></p>