List of usage examples for android.support.v4.app DialogFragment setRetainInstance
public void setRetainInstance(boolean retain)
From source file:name.gumartinm.weather.information.activity.MainTabsActivity.java
@Override public void onResume() { super.onResume(); final SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); final String APPID = sharedPreferences.getString(this.getString(R.string.weather_preferences_app_id_key), "");/*from ww w.j a v a 2s . co m*/ final String noticeKeyPreference = this.getString(R.string.api_id_key_notice_preference_key); final boolean notice = sharedPreferences.getBoolean(noticeKeyPreference, true); if (notice && APPID.isEmpty()) { final FragmentManager fm = this.getSupportFragmentManager(); final Fragment buttonsFragment = fm.findFragmentByTag("noticeDialog"); if (buttonsFragment == null) { final DialogFragment newFragment = APIKeyNoticeDialogFragment .newInstance(R.string.api_id_key_notice_title); newFragment.setRetainInstance(true); newFragment.setCancelable(false); newFragment.show(fm, "noticeDialog"); } } final ActionBar actionBar = this.getActionBar(); // 1. Update title. final DatabaseQueries query = new DatabaseQueries(this.getApplicationContext()); final WeatherLocation weatherLocation = query.queryDataBase(); if (weatherLocation != null) { final String[] array = new String[2]; array[0] = weatherLocation.getCity(); array[1] = weatherLocation.getCountry(); final MessageFormat message = new MessageFormat("{0},{1}", Locale.US); final String cityCountry = message.format(array); actionBar.setTitle(cityCountry); } else { actionBar.setTitle(this.getString(R.string.text_field_no_chosen_location)); } // 2. Update forecast tab text. final String keyPreference = this.getString(R.string.weather_preferences_day_forecast_key); final String value = sharedPreferences.getString(keyPreference, ""); String humanValue = ""; if (value.equals(this.getString(R.string.weather_preferences_day_forecast_five_day))) { humanValue = this.getString(R.string.text_tab_five_days_forecast); } else if (value.equals(this.getString(R.string.weather_preferences_day_forecast_ten_day))) { humanValue = this.getString(R.string.text_tab_ten_days_forecast); } else if (value.equals(this.getString(R.string.weather_preferences_day_forecast_fourteen_day))) { humanValue = this.getString(R.string.text_tab_fourteen_days_forecast); } actionBar.getTabAt(1).setText(humanValue); }