Source:
public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.actionSettings: startActivity(new Intent(this, SettingsActivity.class)); return true; case R.id.actionContact: startActivity(new Intent(this, ContactUsActivity.class)); return true; case R.id.actionSearchLocal: return true; case R.id.actionLogout: this.showLogoutDialog(); return true; case R.id.syncbutton: boolean syncState = OpenMRS.getInstance().getSyncState(); if (syncState) { OpenMRS.getInstance().setSyncState(false); setSyncButtonState(false); showNoInternetConnectionSnackbar(); ToastUtil.showShortToast(getApplicationContext(), ToastUtil.ToastType.NOTICE, R.string.disconn_server); } else if (NetworkUtils.hasNetwork()) { OpenMRS.getInstance().setSyncState(true); setSyncButtonState(true); Intent intent = new Intent(getString(R.string.intent_action_sync_patients)); getApplicationContext().sendBroadcast(intent); ToastUtil.showShortToast(getApplicationContext(), ToastUtil.ToastType.NOTICE, R.string.reconn_server); if (snackbar != null) snackbar.dismiss(); ToastUtil.showShortToast(getApplicationContext(), ToastUtil.ToastType.SUCCESS, R.string.connected_to_server_message); } else { showNoInternetConnectionSnackbar(); } return true; case R.id.actionLocation: if (!locationList.isEmpty()) { locationList.clear(); } Observable<List<Location>> observableList = new LocationDAO().getLocations(); observableList.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(getLocationList()); return true; default: return super.onOptionsItemSelected(item); } }

Target:
public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.actionSettings: startActivityForResult(new Intent(this, SettingsActivity.class), ApplicationConstants.RequestCodes.START_SETTINGS_REQ_CODE); return true; case R.id.actionContact: startActivity(new Intent(this, ContactUsActivity.class)); return true; case R.id.actionSearchLocal: return true; case R.id.actionLogout: this.showLogoutDialog(); return true; case R.id.syncbutton: boolean syncState = OpenMRS.getInstance().getSyncState(); if (syncState) { OpenMRS.getInstance().setSyncState(false); setSyncButtonState(false); showNoInternetConnectionSnackbar(); ToastUtil.showShortToast(getApplicationContext(), ToastUtil.ToastType.NOTICE, R.string.disconn_server); } else if (NetworkUtils.hasNetwork()) { OpenMRS.getInstance().setSyncState(true); setSyncButtonState(true); Intent intent = new Intent("org.openmrs.mobile.intent.action.SYNC_PATIENTS"); getApplicationContext().sendBroadcast(intent); ToastUtil.showShortToast(getApplicationContext(), ToastUtil.ToastType.NOTICE, R.string.reconn_server); if (mSnackbar != null) { mSnackbar.dismiss(); } ToastUtil.showShortToast(getApplicationContext(), ToastUtil.ToastType.SUCCESS, R.string.connected_to_server_message); } else { showNoInternetConnectionSnackbar(); } return true; case R.id.actionLocation: if (!locationList.isEmpty()) { locationList.clear(); } Observable<List<Location>> observableList = new LocationDAO().getLocations(); observableList.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(getLocationList()); return true; default: return super.onOptionsItemSelected(item); } }