I have a Native Module for my React Native app.
From React Native, I call a function in this Native Module, it looks like this (on Android):
@ReactMethod
public void show(
String targetUrl,
Callback onFinishCallback
) {
...
// start a new activity here
// Before exiting the activity, I will invoke the onFinishCallback
}
The function works well for most cases, but after the app gets destroyed by Android System (when it is in background for long time), if I pull the app to foreground again, my new activity will be recreated, but this time, when exiting the activity, I cannot call the onFinishCallback because I cannot keep the reference to this Callback object after app restarted.
Is there any way to serialize the Callback object? So I can deserialize it when the new activity gets recreated and call it consistently.