From: Alexis Laferrière Date: Tue, 17 Mar 2015 18:25:41 +0000 (-0400) Subject: examples/calculator: save and load state on request X-Git-Tag: v0.7.3~21^2~1 X-Git-Url: http://nitlanguage.org examples/calculator: save and load state on request Signed-off-by: Alexis Laferrière --- diff --git a/examples/calculator/src/calculator_android.nit b/examples/calculator/src/calculator_android.nit index 9b79886..ec7b374 100644 --- a/examples/calculator/src/calculator_android.nit +++ b/examples/calculator/src/calculator_android.nit @@ -86,6 +86,32 @@ redef class Activity native.content_view = layout end + redef fun on_save_instance_state(state) + do + super + + var nity = new Bundle.from(state) + nity["context"] = context.to_json + end + + redef fun on_restore_instance_state(state) + do + super + + var nity = new Bundle.from(state) + if not nity.has("context") then return + + var json = nity.string("context") + if json == null then return + + context = new CalculatorContext.from_json(json) + end + + redef fun on_resume + do + display.text = context.display_text + end + redef fun catch_event(event) do if event isa ClickEvent then