@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   if (id == R.id.menu_add_task) {
     onAddNewTask();
     return true;
   } else if (item.getItemId() == R.id.menu_visible_list) {
     Intent settingsIntent = new Intent(getBaseContext(), SyncSettingsActivity.class);
     startActivity(settingsIntent);
     return true;
   } else if (item.getItemId() == R.id.menu_alarms) {
     // set and save state
     boolean activatedAlarms = !item.isChecked();
     item.setChecked(activatedAlarms);
     AlarmBroadcastReceiver.setAlarmPreference(this, activatedAlarms);
     return true;
   } else {
     return super.onOptionsItemSelected(item);
   }
 }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.task_list_activity_menu, menu);

    MenuItem addItem = menu.findItem(R.id.menu_add_task);
    if (addItem != null && mFloatingActionButton != null) {
      // hide menu option to add a task if we have a floating action button
      addItem.setVisible(false);
    }

    // restore menu state
    MenuItem item = menu.findItem(R.id.menu_alarms);
    if (item != null) {
      item.setChecked(AlarmBroadcastReceiver.getAlarmPreference(this));
    }

    // search
    setupSearch(menu);

    return true;
  }