Putting things into place to fix a bug when the app is destroyed while the timer was running.

This commit is contained in:
2025-07-12 13:18:52 -07:00
parent 8da02333df
commit 03380cf023

View File

@@ -207,9 +207,11 @@ public class MainActivity extends AppCompatActivity {
//chronometer = (TextView) findViewById(R.id.chronometer);
String[] time = {Long.toString(milliseconds/(1000*60*60)),
Long.toString((milliseconds/(1000*60)%(60))),
Long.toString((milliseconds/(1000))%60)};
String[] time = {
Long.toString(milliseconds/(1000*60*60)),
Long.toString((milliseconds/(1000*60))%60),
Long.toString((milliseconds/(1000))%60)
};
for (int i = 0; i < time.length; i++){
while (time[i].length() < 2){
@@ -350,7 +352,7 @@ public class MainActivity extends AppCompatActivity {
}
}
private Handler incrementTime = new Handler(){
private final Handler incrementTime = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
@@ -467,6 +469,22 @@ public class MainActivity extends AppCompatActivity {
mediaPlayer.start();
}
// TODO: use this to fix bug when app is closed during a countdown, it opens
// back up with a 0 count but timer is enabled and needs Stopped before the
// edit texts can be used.
private void resetAll() {
setChronometer(0);
setEditTexts("");
setLoopInterval();
start = false;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(keyStartStop, start);
editor.putBoolean(keyAppOpen, start);
editor.putBoolean(keyServiceRunning, start);
editor.apply();
}
@Override
protected void onPause() {
super.onPause();
@@ -494,6 +512,13 @@ public class MainActivity extends AppCompatActivity {
recoverScreen();
}
@Override
protected void onDestroy() {
resetAll();
super.onDestroy();
}
private void flipInputTexts() {
etHours.setEnabled(!start);
etMinutes.setEnabled(!start);