@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { if (REQ_CODE_LOCATION == requestCode) { String location = data.getStringExtra(EXTRA_SELECTED_LOCATION_NAME); long locationId = data.getLongExtra(EXTRA_SELECTED_LOCATION_ID, 0); ShowForecastFragment f = (ShowForecastFragment) getFragmentManager().findFragmentById(R.id.showForecastFragment); if (f != null) { if (location != null) { f.getWeatherForLocation(location); } else if (locationId != 0) { f.getWeatherForLocationId(locationId); } } else { Log.e("MainActivity", "ShowForecastFragment was not found!"); } } } super.onActivityResult(requestCode, resultCode, data); }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.change_units: boolean units = AppSettings.getInstance(this).getBoolean(AppSettings.Key.IS_FAHRENHEIT, false); AppSettings.getInstance(this).put(AppSettings.Key.IS_FAHRENHEIT, !units); item.setChecked(!units); ShowForecastFragment f = (ShowForecastFragment) getFragmentManager().findFragmentById(R.id.showForecastFragment); if (f != null) { f.getWeatherForLocation(); } // Update all widgets updateAllWidgets(); return true; default: return super.onOptionsItemSelected(item); } }