I am failing to understand the difference between the usage of these two different imports for UiThread annotations:
- org.androidannotations.annotations.UiThread
- android.support.annotation.UiThread
Any help will be appreciated.
I am failing to understand the difference between the usage of these two different imports for UiThread annotations:
Any help will be appreciated.
The @UiThread
annotation from the org.androidannotations
library forces the method to be executed on the UI thread (build-time code generation).
While the same annotation from the support library (android.support.annotation
) merely indicates, that the code should only be called on the UI thread, so the IDE will be able to warn the developer in case this requirement is violated.
From the docs
The @UiThread annotation indicates that a method will run in the ui thread. "source"
Denotes that the annotated method or constructor should only be called on the UI thread. If the annotated element is a class, then all methods in the class should be called on the UI thread. "source"
so, the first annotation will make sure that a method will be called in UIThread which ever Thread you are calling from. While the second one is a marker, maybe for lint, to check if the method is called from UIThread or not, and will show error accordingly.