pub struct OnCreateState<'a> { /* private fields */ }Expand description
The state passed to the optional android_on_create entry point if
available.
This gives access to the Java VM, the Java Activity and any saved state
from a previous instance of the Activity that was saved via the
onSaveInstanceState callback.
Each time android_on_create is called it will receive a new Activity
reference.
See the top-level android-activity documentation for more details
on android_on_create.
Implementations§
Source§impl<'a> OnCreateState<'a>
impl<'a> OnCreateState<'a>
Sourcepub fn vm_as_ptr(&self) -> *mut c_void
pub fn vm_as_ptr(&self) -> *mut c_void
Returns a pointer to the Java Virtual Machine, for making JNI calls
If you use the jni crate, you can wrap this pointer as a JavaVM via:
let vm = unsafe { JavaVM::from_raw(on_create_state.vm_as_ptr().cast()) };Sourcepub fn activity_as_ptr(&self) -> *mut c_void
pub fn activity_as_ptr(&self) -> *mut c_void
Returns an (unowned) JNI global object reference for this Activity
as a pointer
If you use the jni crate, you can cast this as a JObject reference
via:
let vm = unsafe { JavaVM::from_raw(on_create_state.vm_as_ptr().cast()) };
let _res = vm.attach_current_thread(|env| -> jni::errors::Result<()> {
let activity = on_create_state.activity_as_ptr() as jni::sys::jobject;
// SAFETY: The reference / pointer is valid at least until we return from `android_on_create`
let activity = unsafe { env.as_cast_raw::<JObject>(&activity)? };
// Do something with `activity` here
Ok(())
});§JNI Safety
It is not specified whether this will be a global or local reference and in any case you must treat is as a reference that you do not own and must not attempt to delete it.
- Don’t wrap the reference as a
Globalwhich would try to delete the reference when dropped. - Don’t wrap the reference in an
Autowhich would treat the reference like a local reference and try to delete it when dropped.
Sourcepub fn saved_state(&self) -> &[u8] ⓘ
pub fn saved_state(&self) -> &[u8] ⓘ
Returns the saved state of the Activity as a byte slice, which may be
empty if there is no saved state.