Haakon,
There is one thing you have to watch out for on Android that behaves differently compared to iOS.
The CoronaRuntime and its LuaState is tied to the CoronaActivity’s lifecycle and not the Application. That is, when you launch a new CoronaActivity, then a new CoronaRuntime and LuaState object gets created. When you tap “back” to exit the CoronaActivity, the CoronaRuntime and its LuaState are disposed of and dereferenced to be garbage collected, but your app’s process, its Application object, and all of its static variables remain alive. So, the next time you tap your app icon to launch a new CoronaActivity (while your app process is still running in the background), a new CoronaRuntime and LuaState object gets created.
The thing you got to watch out for then is that the CoronaRuntimeTaskDispatcher can only send tasks to the CoronaRuntime that you fed into its constructor. Once that CoronaRuntime has been disposed of, which happens when you back out of a CoronaActivity, then the dispatcher will stop working and no-op when you call its send() method from then on, which is by design.
Note: You can determine if the dispatcher’s target is still available (ie: not disposed of) by calling the dispatcher’s isRuntimeAvailable() method.
http://docs.coronalabs.com/native/android/html/com/ansca/corona/CoronaRuntimeTaskDispatcher.html
This means that the next time a CoronaActivity gets launched, you’ll need to replace your dispatcher object with a new one that target’s the CoronaActivity’s new CoronaRuntime object. So, it’s okay to store the dispatcher object to a static variable. Just make sure to update it.
Setting up a global CoronaRuntimeListener like you’re doing is the easiest way to handle runtime events. It’s onLoaded() method will be called every time a new CoronaRuntime object has been created, so that is where you need to create a new dispatcher and replace your old one.
Anyways, I hope this helps!
[import]uid: 32256 topic_id: 33865 reply_id: 137458[/import]