Asynchronous callbacks from other activities

When calling a function in an external Activity, the CoronaRuntimeTask is never executed.

Thoughts?

Here is code that demonstrates what I have observed.

[code]
public class SomeActivity extends Activity {

private com.naef.jnlua.LuaState luaState;

public void performCallback() {
final com.ansca.corona.CoronaRuntimeTaskDispatcher dispatcher = new com.ansca.corona.CoronaRuntimeTaskDispatcher(luaState);

// Still good…

com.ansca.corona.CoronaEnvironment.getCoronaActivity().runOnUiThread(new Runnable() {
@Override
public void run() {

// Still good…

com.ansca.corona.CoronaRuntimeTask task = new com.ansca.corona.CoronaRuntimeTask() {
@Override
public void executeUsing(com.ansca.corona.CoronaRuntime runtime) {
// NOT CALLED
}
};

dispatcher.send(task);
}
});

// Return 0 since this Lua function does not return any values.
return 0;
}
}
[/code] [import]uid: 169919 topic_id: 35742 reply_id: 335742[/import]

This is by design. Your CoronaRuntimeTask objects will not be executed until the Corona runtime has been resumed, which won’t happen until the CoronaActivity has been displayed in the foreground.

That said, it is okay to queue these CoronaRuntimeTask objects while Corona is suspended. They will all be executed in the order they were sent by the dispatcher once Corona has been resumed. [import]uid: 32256 topic_id: 35742 reply_id: 142151[/import]

It actually never ends up running. Even when that activity calls “finish();” and the main CoronaActivity resumes, there is no callback fired. [import]uid: 169919 topic_id: 35742 reply_id: 142170[/import]

This means that the LuaState object that you are holding a reference to along with its CoronaRuntime has been disposed of. You can test for this by calling the dispatcher’s [lua]isRuntimeAvailable()[/lua] method as documented here…
http://docs.coronalabs.com/native/android/html/com/ansca/corona/CoronaRuntimeTaskDispatcher.html#isRuntimeAvailable()

You should actually never hold on to a LuaState object reference via a member variable because it can be disposed of when the CoronaActivity has been dismissed. An exception/crash will occur if you call the LuaState’s methods after it has been disposed of… or if you make calls to it from a thread other than the CoronaRuntime thread. It’s better to hold on to a reference to a CoronaRuntimeTaskDispatcher instead because it knows how to sync back to the main thread and safely no-ops when the CoronaRuntime and its LuaState has been disposed of.

Also, anytime you Back out of the CoronaActivity or call its dismiss() method will cause its associated CoronaRuntime and LuaState objects to be disposed of. So, the next time you launch the CoronaActivity a new CoronaRuntime and LuaState object will be created. So, I’m thinking you must be holding on to an old reference.
[import]uid: 32256 topic_id: 35742 reply_id: 142173[/import]

This is by design. Your CoronaRuntimeTask objects will not be executed until the Corona runtime has been resumed, which won’t happen until the CoronaActivity has been displayed in the foreground.

That said, it is okay to queue these CoronaRuntimeTask objects while Corona is suspended. They will all be executed in the order they were sent by the dispatcher once Corona has been resumed. [import]uid: 32256 topic_id: 35742 reply_id: 142151[/import]

It actually never ends up running. Even when that activity calls “finish();” and the main CoronaActivity resumes, there is no callback fired. [import]uid: 169919 topic_id: 35742 reply_id: 142170[/import]

This means that the LuaState object that you are holding a reference to along with its CoronaRuntime has been disposed of. You can test for this by calling the dispatcher’s [lua]isRuntimeAvailable()[/lua] method as documented here…
http://docs.coronalabs.com/native/android/html/com/ansca/corona/CoronaRuntimeTaskDispatcher.html#isRuntimeAvailable()

You should actually never hold on to a LuaState object reference via a member variable because it can be disposed of when the CoronaActivity has been dismissed. An exception/crash will occur if you call the LuaState’s methods after it has been disposed of… or if you make calls to it from a thread other than the CoronaRuntime thread. It’s better to hold on to a reference to a CoronaRuntimeTaskDispatcher instead because it knows how to sync back to the main thread and safely no-ops when the CoronaRuntime and its LuaState has been disposed of.

Also, anytime you Back out of the CoronaActivity or call its dismiss() method will cause its associated CoronaRuntime and LuaState objects to be disposed of. So, the next time you launch the CoronaActivity a new CoronaRuntime and LuaState object will be created. So, I’m thinking you must be holding on to an old reference.
[import]uid: 32256 topic_id: 35742 reply_id: 142173[/import]