diff --git a/README.md b/README.md index 1fbe705f6c1f24b55e91f2bf02b5b7d3b10b0561..65fa86c7bbb031b243eef12527aa098dc49319b0 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,4 @@ http://stackoverflow.com/questions/4885254/string-format-to-format-double-in-jav ## Known Problems, Issues, And/Or Errors in the Program -* I can't seem to figure out how to properly use savedInstanceState to keep program status through rotations. I'm pretty sure it's because I'm trying to pass an array of booleans. -* To elaborate, my initial problem is this: the only thing (seemingly) not saved on rotate are the conversion display strings, which are only generated if all booleans come back true true and a button is pressed. I COULD potentially just force the string to display on rotate, but that just delays the issue. IE: to display another, seperate equation, the user will have to click every single group again to trigger the 3 booleans anyways (...at least I think they will? This savedInstanceState logic is confusing). Therefore it's best to either 1) carry over all three booleans or 2) reset the entire program (including button selections) on rotate. - -* In an attempt to carry over these three booleans, an array seemed like the only solution. Via debugging, it appears that the array does infact seem to save all appropriate values just before rotate, as intended. However, the problem seems to be in calling them back up in the onCreate method. Getting a saved instance state requires passing the Key_Index string (which points to the value you want to use), and then the "default to if no value" parameter, right? So then to call a specific index of the savedBooleanStateArray, I would need to somehow modify Key_Index to point at a particular index? I think? I don't know...this was confusing enough when passing a single variable, but I can't think of a reasonable way to make this program work with only passing 1. \ No newline at end of file diff --git a/app/src/main/java/edu/kvcc/cis298/cis298assignment2/TemperatureConverter.java b/app/src/main/java/edu/kvcc/cis298/cis298assignment2/TemperatureConverter.java index a79a7032453c78c0be63709669eb1d54f4089f8d..b4386cfc6d8b65955b38804eb571a5db346d82a8 100644 --- a/app/src/main/java/edu/kvcc/cis298/cis298assignment2/TemperatureConverter.java +++ b/app/src/main/java/edu/kvcc/cis298/cis298assignment2/TemperatureConverter.java @@ -317,12 +317,11 @@ public class TemperatureConverter extends AppCompatActivity { if (savedInstanceState != null) { // Loads saved value of initial variables. - // ...If KEY_INDEX is an index comprised of a string that points to the array, how the - // heck do use it to point to an index in the array? I'm calling an index within an - // index? wat. - mConvertButtonIsClicked = savedInstanceState.getBoolean(KEY_INDEX, false); - mInitialGroupChecked = savedInstanceState.getBoolean(KEY_INDEX, false); - mConvertGroupChecked =savedInstanceState.getBoolean(KEY_INDEX, false); + boolean[] savedStateBool = savedInstanceState.getBooleanArray(KEY_INDEX); + + mConvertButtonIsClicked = savedStateBool[0]; + mInitialGroupChecked = savedStateBool[1]; + mConvertGroupChecked = savedStateBool[2]; // Checks to see if user has input a number. if (mUserInputEditText.length() > 0) { @@ -423,7 +422,8 @@ public class TemperatureConverter extends AppCompatActivity { Log.d(TAG, "onSaveInstanceState"); // Saves current state booleans since all user input stays on rotation. - // Keeping the booleans SHOULD make the conversions keep showing even on rotation. + // Keeping the booleans will ensure the conversions show even on rotation. + // Uses an array over multiple puts, since the booleans are all similarly related. mCurrentStatus[0] = mConvertButtonIsClicked; mCurrentStatus[1] = mInitialGroupChecked; mCurrentStatus[2] = mConvertGroupChecked;