friendz: save and restore music+sfx mute state
[nit.git] / lib / android / bundle / bundle.nit
index 76babb4..82acbec 100644 (file)
@@ -425,7 +425,7 @@ end
 
 # A class mapping `String` keys to various value types
 class Bundle
-       private var native_bundle: NativeBundle = new NativeBundle is lazy
+       private var native_bundle: NativeBundle = (new NativeBundle).new_global_ref is lazy
 
        # Get a new `Bundle` wrapping `native_bundle`
        init from(native_bundle: NativeBundle) do self.native_bundle = native_bundle
@@ -543,13 +543,15 @@ class Bundle
        # Returns `null` if none or if it's the wrong value type
        fun string(key: String): nullable String
        do
-               sys.jni_env.push_local_frame(1)
-               var return_value = native_bundle.get_string(key.to_java_string).to_s
-               sys.jni_env.pop_local_frame
+               sys.jni_env.push_local_frame(2)
 
-               if return_value == "" then return null
+               var jstr = native_bundle.get_string(key.to_java_string)
+               var str = null
+               if not jstr.is_java_null then str = jstr.to_s
 
-               return return_value
+               sys.jni_env.pop_local_frame
+
+               return str
        end
 
        # Retrieves the `Bool` value corresponding to the given key