Skip to content

Commit 772f4ad

Browse files
committed
updated example
-updated example to prevent reinitializing localWeather -calling fetchLocation only and setting weatherReady to false while fetching new location
1 parent 669dc5f commit 772f4ad

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

app/src/main/java/de/interaapps/localweather/MainActivity.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ private void initialize() {
7373
weatherWindDeg = findViewById(R.id.weather_wind_deg);
7474
weatherSunrise = findViewById(R.id.weather_sunrise);
7575
weatherSunset = findViewById(R.id.weather_sunset);
76-
}
77-
78-
private void initializeLogic() {
79-
Timer timer = new Timer ();
80-
TimerTask tenMinTask = new TimerTask () {
81-
@Override
82-
public void run () {
83-
updateLocalWeather();
84-
}
85-
};
86-
timer.schedule(tenMinTask, 0, 1000*60*10); //1000*60 = 1min *10 = 10min
87-
}
88-
89-
private void updateLocalWeather() {
9076
localWeather = new LocalWeather(this,
9177
"OpenWeatherApiKey",
9278
true,
@@ -114,8 +100,18 @@ public void onWeatherSuccess() {
114100
updateWeatherDetails();
115101
}
116102
});
103+
}
117104

118-
localWeather.fetchLocation();
105+
private void initializeLogic() {
106+
Timer timer = new Timer ();
107+
TimerTask tenMinTask = new TimerTask () {
108+
@Override
109+
public void run () {
110+
weatherReady = false;
111+
localWeather.fetchLocation();
112+
}
113+
};
114+
timer.schedule(tenMinTask, 0, 1000*60*10); //1000*60 = 1min *10 = 10min
119115
}
120116

121117
private void updateWeatherDetails() {

0 commit comments

Comments
 (0)