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:
-
ActionBarImplBase can only be used with a compatible window decor layout
-
Titanium iOS builder script
-
Use view from custom module inside Titanium ListViewItem
-
Flurry Android 3.2.0 SDK for Titanium module
-
Efficient code
-
Object oriented Javascript with CommonJS in Titanium app
-
Titanium Studio mark occurences
-
Titanium Android keystore
-
Add project as library – Titanium module (Android)
-
Indirect code execution flow
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
}
});