title: Using Android menu code in common Utils File
body: <p>I am trying to implement my menu in a <code>Utils.java</code> file. Well, so far so good, the menu is appearing as it should although when I click on any menu item, the application stops working. I don't seem to find where the issue is and I would be grateful for your advice. The code for my menu, utils and activity files is as below:</p>
  
  <p><strong>Utils.java</strong></p>
  
  <pre><code>package com.package.name;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.Intent;
  
  public class Utils extends Activity{
  
  private Context _context;
  
  public Utils(Context context){
      this._context = context;
  }
  
  public void menuSwitch(int item) {
         switch (item) {
              case R.id.menu_one:
                  startActivity(new Intent(getApplicationContext(),
                          MainActivity.class));
              case R.id.menu_two:
                  startActivity(new Intent(getApplicationContext(),
                          MessageActivity.class));
              case R.id.menu_three:
                  startActivity(new Intent(getApplicationContext(),
                          LocateActivity.class));
              case R.id.menu_four:
                  startActivity(new Intent(this,
                          AboutActivity.class));
      }
  }
  }
  </code></pre>
  
  <p><strong>menu_main.xml</strong></p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"&gt;
  &lt;item android:id="@+id/menu_one" android:title="@string/menu_one" /&gt;
  &lt;item android:id="@+id/menu_two" android:title="@string/menu_two" /&gt;
  &lt;item android:id="@+id/menu_three" android:title="@string/menu_three" /&gt;
  &lt;item android:id="@+id/menu_four" android:title="@string/menu_four" /&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>menuActivity.java</strong></p>
  
  <pre><code>package com.package.name;
  
  import android.app.ListActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  
  
  public class DatabaseActivity extends ListActivity {
  
  Utils util;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_database);
  
      util = new Utils(this);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      util.menuSwitch(item.getItemId());
      return true;
  }
  }
  </code></pre>