addEventListener

fun MMKV.addEventListener(listener: (String) -> Unit): () -> Unit

Adds a listener to receive callbacks when any key in this MMKV instance changes.

The listener is invoked with the changed key. Returned function can be called to remove the listener.

Note: Only MMKV instances created via top.kagg886.mkmb.ext.MMKV.defaultMMKV or top.kagg886.mkmb.ext.MMKV.mmkvWithID support this method. Otherwise an error is thrown.

Return

A function that removes this listener when invoked.

Parameters

listener

Callback receiving the changed key.

Throws

if this MMKV is not a DelegatedMMKV.