Method calling thread for Titanium module (Android)
On 8 May 2014 in TechWhen creating method for a Titanium module in Android, using @Kroll.method annotation, this method will be invoked on KrollRuntimeThread. This is important to know if that method is accessing UI component, such as TextView or WebView, since all UI related components must be handled on main thread.
@Kroll.method annotation have one convenient argument that allow method to be called on UI thread
@Kroll.method(runOnUiThread=true) public void show() {}
However, it is deprecated – as noted on Specific Changes no. 18 of Android Module Porting Guide , you can use TiMessenger class.
Or, easier way is to use Activity runOnUiThread method
@Kroll.method public void show() {   getActivity().runOnUIThread(new Runnable() {     @Override     public void run() {       // code here     }   }); }
Related posts:
-
Activity & fragment lifecycle events
-
Flurry Android 3.2.0 SDK for Titanium module
-
Android BOOT_COMPLETED handler module
-
Restart ADB
-
Titanium app components interaction using events and callbacks
-
Titanium Android keystore
-
Indirect code execution flow
-
ActionBarImplBase can only be used with a compatible window decor layout
-
Add project as library – Titanium module (Android)
-
Android Progress Notification module
Filed under Tech with tags Android, Java, Thread, Titanium Mobile, Titanium Module
I also like using this as getActivity().runOnUIThread is not always working:
TiUIHelper.runUiDelayedIfBlock(new Runnable() {
@Override
public void run() {
// code here
}
});