android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:logo="@drawable/ic_launcher"
- android:theme="@style/AppTheme" >
+ android:theme="@style/AppTheme"
+ android:name="de.example.exampletdd.WeatherInformationApplication" >
<!--
<activity
android:name="de.example.exampletdd.WeatherInformationActivity"
<activity
android:name="de.example.exampletdd.WeatherTabsActivity"
android:hardwareAccelerated="false"
- android:uiOptions="splitActionBarWhenNarrow" >
+ android:uiOptions="splitActionBarWhenNarrow"
+ android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
--- /dev/null
+package de.example.exampletdd;
+
+import android.app.Application;
+import de.example.exampletdd.model.GeocodingData;
+
+public class WeatherInformationApplication extends Application {
+ private GeocodingData mGeocodingData;
+
+ protected void setGeocodingData(final GeocodingData geocodingData) {
+ this.mGeocodingData = geocodingData;
+ }
+
+ protected GeocodingData getGeocodingData() {
+ return this.mGeocodingData;
+ }
+}
import de.example.exampletdd.service.WeatherServicePersistenceFile;
public class WeatherTabsActivity extends FragmentActivity {
- private static final String TAG = "WeatherTabsActivity";
private static final int NUM_ITEMS = 2;
private MyAdapter mAdapter;
private ViewPager mPager;
- private GeocodingData mGeocodingData;
private WeatherServicePersistenceFile mWeatherServicePersistenceFile;
@Override
super.onCreate(savedInstanceState);
this.setContentView(R.layout.fragment_pager);
+ this.mWeatherServicePersistenceFile = new WeatherServicePersistenceFile(this);
this.mAdapter = new MyAdapter(this.getSupportFragmentManager());
this.mPager = (ViewPager)this.findViewById(R.id.pager);
@Override
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
if (savedInstanceState != null) {
- this.mGeocodingData = (GeocodingData) savedInstanceState
- .getSerializable("GEOCODINGDATA");
+ final WeatherInformationApplication application = (WeatherInformationApplication) this
+ .getApplication();
+ application.setGeocodingData((GeocodingData) savedInstanceState
+ .getSerializable("GEOCODINGDATA"));
}
super.onRestoreInstanceState(savedInstanceState);
}
actionBar.getTabAt(1).setText(humanValue);
- final Intent intent = new Intent(this, WeatherInformationBatch.class);
- this.startService(intent);
+ final WeatherInformationApplication application = (WeatherInformationApplication) this
+ .getApplication();
+ if (application.getGeocodingData() != null) {
+ // If there is previous value.
+ final GeocodingData geocodingDataFile = this.mWeatherServicePersistenceFile
+ .getGeocodingData();
+ if (!application.getGeocodingData().equals(geocodingDataFile)) {
+ // Just update when value changed.
+ application.setGeocodingData(geocodingDataFile);
+ final Intent intent = new Intent(this, WeatherInformationBatch.class);
+ this.startService(intent);
+ }
+ } else {
+ // There is no previous value.
+ application.setGeocodingData(this.mWeatherServicePersistenceFile.getGeocodingData());
+ final Intent intent = new Intent(this, WeatherInformationBatch.class);
+ this.startService(intent);
+ }
// if (geocodingData != null) {
// if ((this.mGeocodingData == null) || (!this.mGeocodingData.equals(geocodingData))) {
@Override
public void onSaveInstanceState(final Bundle savedInstanceState) {
- savedInstanceState.putSerializable("GEOCODINGDATA", this.mGeocodingData);
+ final WeatherInformationApplication application = (WeatherInformationApplication) this
+ .getApplication();
+ savedInstanceState.putSerializable("GEOCODINGDATA", application.getGeocodingData());
super.onSaveInstanceState(savedInstanceState);
}