examples/calculator: save and load state on request
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 17 Mar 2015 18:25:41 +0000 (14:25 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 18 Mar 2015 12:37:57 +0000 (08:37 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/calculator/src/calculator_android.nit

index 9b79886..ec7b374 100644 (file)
@@ -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