package space.themelon.dispatchtest;
import android.util.Log;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.Form;
@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
nonVisible = true)
@SimpleObject(external = true)
public class DispatchTest extends AndroidNonvisibleComponent {
private static final String TAG = "DispatchTest";
public DispatchTest(Form form) {
super(form);
}
@SimpleFunction
public void DispatchEvent() {
MyEvent("hello world");
}
@SimpleEvent
public void MyEvent(String arg) {
boolean dispatched = EventDispatcher.dispatchEvent(this, "MyEvent", arg);
Log.d(TAG, "Event Dispatched = " + dispatched);
}
}
The above code contains simple blocks, a block called DispatchEvent()
that calls MyEvent("hello world")
. This is expected to work correctly, but the following behaviour happens:
-
When
DispatchEvent()
block is called fromInitialize
event block,EventDispatcher.dispatchEvent()
returnsfalse
. -
When
DispatchEvent()
block is called on an event of a Button click, the event gets dispatched successfully.
[kumaraswamy@ekita ~]$ adb logcat -s DispatchTest
--------- beginning of main
05-19 22:12:29.488 5765 5765 D DispatchTest: Event Dispatched = false
05-19 22:12:31.039 5765 5765 D DispatchTest: Event Dispatched = true
DispatchTest.aia (5.7 KB)
space.themelon.dispatchtest.aix (5.0 KB)
Tested in compiled application.