NME initialization mobile component for Android

63 views
Skip to first unread message

David Mouton

unread,
Dec 12, 2014, 9:59:33 AM12/12/14
to haxe...@googlegroups.com
Hi,
I'm trying to init my component at statup in MainActivity like that :

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
        this.myComponement = (SakuraEditor)getFragmentManager().findFragmentById(R.id.fragment1);
        this.myComponement.setConfig(Mock.getConfig()); // throw an exception
        
}

But it doesn't work like if my component wasn't ready yet.

Doing the same things later works perfectly (with a button for exemple)

Anyone have an idea to initialize my component ?

Daniel Uranga

unread,
Dec 12, 2014, 1:27:00 PM12/12/14
to haxe...@googlegroups.com
Maybe you could send some "ready" signal from the Haxe side at startup, and wait for it on the Java side.

Hugh

unread,
Dec 16, 2014, 12:30:10 AM12/16/14
to haxe...@googlegroups.com
This initialization order is complicated by threading on android.
Calling into your component requires the 'haxeCallbackObject' to be set in the CLASS_JAR.java template - from which your component will inherit.
This get sets from the ApplicationMain.setAndroidViewHaxeObject call in the ApplicationMain.hx template.
This gets called from the ApplicationDocument auto-boot code, which constructs your object, and then sets this value.
However the auto-boot code must wait until the opengl context is ready because your class can make opengl calls in its constructor, so this value is delayed until the thread that runs the display of your view is ready.
It is theoretically possible to set various static values in haxe before the graphics are running, but I have not investigated this.

I think the most robust solution would be to pull the config from java via a "getConfig" call in your constructor, rather than push the value from java onto haxe code.
Hugh

David Mouton

unread,
Dec 16, 2014, 12:26:01 PM12/16/14
to haxe...@googlegroups.com
Ok,
And do you think that it's possible to use event handling, signals, or callback between my java app and my haxe component ?

Hugh

unread,
Dec 16, 2014, 11:38:45 PM12/16/14
to haxe...@googlegroups.com
Yes, this is certainly possible.
You can perform your function (setContext) at the right thread by wrapping it in a "Runnable" and using the GameActivity "sendToView".
This will then get run from haxe's main thread, sometime between refreshes, when the callbacks should be good.
If you want something done early, you can make the call from the main haxe class constructor and do some synchronizing in the java thread.

Hugh

David Mouton

unread,
Dec 18, 2014, 3:25:48 AM12/18/14
to haxe...@googlegroups.com
Mmm, not sure what what to do.
I 'll try to implement event handling with polling from the application.
It could be great if my haxe component could access his host properties and functions.
Reply all
Reply to author
Forward
0 new messages