Use json to save instance state
This commit is contained in:
parent
fe4727ec30
commit
7ee8d6a02a
2 changed files with 20 additions and 0 deletions
|
@ -290,6 +290,7 @@ class MainActivity : SimpleActivity(), Calculator {
|
|||
// ****** ADD ONSAVEINSTANCESTATE FUNCTION ******
|
||||
override fun onSaveInstanceState(bundle: Bundle) {
|
||||
super.onSaveInstanceState(bundle)
|
||||
/*
|
||||
bundle.putString("res", calc.mResult)
|
||||
bundle.putString("savedPreviousCalculation", calc.previousCalculation)
|
||||
bundle.putString("savedLastKey", calc.lastKey)
|
||||
|
@ -297,6 +298,9 @@ class MainActivity : SimpleActivity(), Calculator {
|
|||
bundle.putDouble("savedBaseValue", calc.baseValue)
|
||||
bundle.putDouble("savedSecondValue", calc.getSecondValueV2())
|
||||
bundle.putString("savedInputDisplayedFormula", calc.inputDisplayedFormula)
|
||||
*/
|
||||
//JSON
|
||||
bundle.putString("myJsonObject", calc.getjson())
|
||||
}
|
||||
//============================================================
|
||||
}
|
||||
|
|
|
@ -484,4 +484,20 @@ class CalculatorImpl(
|
|||
return this.secondValue
|
||||
}
|
||||
|
||||
//JSON
|
||||
public fun getJson() : String
|
||||
{
|
||||
val jsonObject = buildJsonObject{
|
||||
put("res", mResult)
|
||||
put("savedPreviousCalculation", previousCalculation)
|
||||
put("savedLastKey", lastKey)
|
||||
put("savedLastOperation", lastOperation)
|
||||
put("savedBaseValue", baseValue)
|
||||
put("savedSecondValue", secondValue)
|
||||
put("savedInputDisplayedFormula", inputDisplayedFormula)
|
||||
return jsonObject.toString()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue