final String fileName = MessageFormat.format(WIDGET_CURRENT_DATA_FILE, appWidgetId);
- try {
- this.removeFile(fileName);
- } catch (final IOException e) {
- Log.e(TAG, "removeWidgetCurrentData exception: ", e);
- }
+ this.removeFile(fileName);
}
public void saveForecast(final Forecast forecast) {
}
}
- private void removeFile(final String fileName) throws IOException {
+ private void removeFile(final String fileName) {
final File filesDir = this.context.getFilesDir();
final File file = new File(filesDir, fileName);
- if (!file.delete()) {
- throw new IOException("PermanentStorage, remove file error");
- }
+ file.delete();
}
}
import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
-import java.util.Date;
import java.util.Locale;
public class WidgetIntentService extends IntentService {
private static final String TAG = "WidgetIntentService";
- private static final long UPDATE_TIME_RATE = 86400000L;
public WidgetIntentService() {
super("WIS-Thread");
final boolean isRefreshAppWidget = intent.getBooleanExtra("refreshAppWidget", false);
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
- // Nothing to do. Something went wrong. Show error.
+ // Nothing to do. Something went wrong.
return;
}
if (weatherLocation == null) {
// Nothing to do. Show error.
final RemoteViews view = this.makeErrorView(appWidgetId);
+
+ final PermanentStorage store = new PermanentStorage(this.getApplicationContext());
+ store.removeWidgetCurrentData(appWidgetId);
+
this.updateWidget(view, appWidgetId);
return;
}
} else {
// Show error.
view = this.makeErrorView(appWidgetId);
+
+ store.removeWidgetCurrentData(appWidgetId);
}
this.updateWidget(view, appWidgetId);
} else {
RemoteViews view;
+ final PermanentStorage store = new PermanentStorage(this.getApplicationContext());
final Current current = this.getRemoteCurrent(weatherLocation);
if (current != null) {
// Update UI.
view = this.makeView(current, weatherLocation, appWidgetId);
- final PermanentStorage store = new PermanentStorage(this.getApplicationContext());
store.saveWidgetCurrentData(current, appWidgetId);
} else {
// Show error.
view = this.makeErrorView(appWidgetId);
+
+ store.removeWidgetCurrentData(appWidgetId);
}
this.updateWidget(view, appWidgetId);
}